homepage Welcome to WebmasterWorld Guest from 54.161.155.142
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
Link to a file anywhere on site
using asp.net usercontrols
Red_Eye




msg:954521
 3:32 pm on Sep 16, 2004 (gmt 0)

I am using a usercontrol to maintain my meta tags on my site. In the usercontrol I link to the style sheet. Which is fine so long as the user control is used in pages at the root of the site however if I use it in a page in the admin folder I need to change the path to the style sheet eg ../style.css rather than style.css. Is there anyway using asp.net to map the location of the style sheet so it can be found from where anywhere.

 

TheNige




msg:954522
 8:44 pm on Sep 16, 2004 (gmt 0)

either store your root domain name such as "http://www.example.com/" in your config and then just plug it in to your links so you always reference the absolute path.

Or use methods such as Request.URL to figure it out...and still plug it into.

I'm not sure if it is possible for use in the CSS link but you can try "~/yourstylesheet.css"...the tilde works in some ASP.Net instances to reference back to the root.

[edited by: Xoc at 1:22 am (utc) on Sep. 17, 2004]
[edit reason] changed to example.com [/edit]

elmarpanzenberger




msg:954523
 10:27 am on Sep 20, 2004 (gmt 0)

Use full URL for your stylesheet:
<link href="http://www.example.com/style.css" rel="stylesheet" type="text/css" />
Should work

[edited by: Xoc at 3:18 pm (utc) on Sep. 21, 2004]
[edit reason] changed to use example.com [/edit]

Red_Eye




msg:954524
 11:55 am on Sep 21, 2004 (gmt 0)

Thanks for your replies are there any reason why absolute URL's shouldn't be used. I have always used relative url's which are only a problem in situations as these.

TheNige




msg:954525
 8:43 pm on Sep 21, 2004 (gmt 0)

Absolute paths are never bad...unless you hard code them. That is why I suggest storing the value of your root domain name in the Web.Config or other place where you can reference it and then plug it into your code.

store something like WebRoot = "http://www.example.com"

So, if you ever change domain names you just go to the config file and change the value instead of througout your code. There are also routines to parse out the domain name root from the server variables, etc.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved