4

So, I thought I'd try my luck on ASP.NET. I didn't get very far before I found my first problem.

I have a folder layout like so:

\
->Admin
-->Admin.Aspx

->CSS
-->Style.css

->Images
-->bg.gif

Default.aspx
Default.master

Both admin.aspx and default.aspx use the default.master page, which contains the line:

<link rel="stylesheet" type="text/css" href="CSS/Style.css" media="screen" />

This works for the default.aspx page, because the path is valid, but for the admin page it's not.

Is there any special character, like ~ for home in Linux, to indicate the root path? I can't use just a slash, because the website maybe under a sub folder when hosted.

Hopefully I've explained myself so you can understand what I need to do :)

I guess it's more an HTML issue than an ASP issue.

1 Answer 1

5

If your <head></head> tag contains runat="server" (which IIRC it does by default) you can simply specify it as:

<link rel="stylesheet" type="text/css" href="~/CSS/Style.css" media="screen" />
Sign up to request clarification or add additional context in comments.

5 Comments

Don't you need runat=server with the ~/ reference?
I seem to remember having seen that having it on the head tag is sufficient, but since you mention it I'll just try it out...
Yes having it on head will do the trick: <head runat="server"> <link rel="stylesheet" type="text/css" href="~/CSS/Style.css" media="screen" /> </head> yields: <head><link rel="stylesheet" type="text/css" href="../CSS/Style.css" media="screen" /></head> when my page is in a subfolder to the root
Wow, I didn't know having the head to be "runat=server" makes its child elements behave almost like server controls. Glad I read this answer.
Sure do :) same if you have <table runat="server"><tr><td></td></tr></table> your <tr> and <td> will get you a complete HtmlTable structure with HtmlTableRow's and HtmlTableCell's

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.