Welcome to WebmasterWorld Guest from 54.234.244.30

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)

Full Member

10+ Year Member

joined:Sept 24, 2002
posts:214
votes: 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.
8:44 pm on Sept 16, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 30, 2003
posts:374
votes: 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]

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

Junior Member

10+ Year Member

joined:June 11, 2003
posts:58
votes: 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]

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

Full Member

10+ Year Member

joined:Sept 24, 2002
posts:214
votes: 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.
8:43 pm on Sept 21, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 30, 2003
posts:374
votes: 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.