Welcome to WebmasterWorld Guest from 174.129.151.95

Forum Moderators: ocean10000

Message Too Old, No Replies

Link to a file anywhere on site

using asp.net usercontrols

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

10+ Year Member



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.
8:44 pm on Sep 16, 2004 (gmt 0)

10+ Year Member



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]

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

10+ Year Member



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]

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

10+ Year Member



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.
8:43 pm on Sep 21, 2004 (gmt 0)

10+ Year Member



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.