2

I had an error in my asp website when I deployed it to IIS6 telling me that I cannot use a leading .. to exit above the top directory. I searched around google and viewed similar questions posted here at stackoverflow and saw recommendations to replace my relative paths ... with ~.

Here is the path for my CSS folder: LMS\assets\css
Where the page is located that tries to access the CSS: LMS\MasterPages
My project structure:
LMS
  -->assets
        -->css
  -->MasterPages
        -->Default.aspx

However, I can't seem to get my paths working. My Default.aspx cannot find my CSS file. Here is an example:
Working:<link href="../assets/css/globalStyles.css" rel="stylesheet" runat="server"/>

Alt 1:href="~/assets/css/globalStyles.css"
Alt 2:href="~\\assets\\css\\globalStyles.css"
Alt 3:href="<%= Page.ResolveUrl("~/assets/css/globalStyles.css") %>"

All of these alternatives don't work. When I debug my site, no styles are present and all are just plain texts. Google Chrome pointed out that my path was being read incorrectly. It was read as:
http://localhost:2981/LMS/Admin/~/assets/css/globalStyles.css.


Can share some thoughts on why this is happening? Why can't my page find my CSS files? I even tried to bind the Page Header in page load but its still not working.

Some ideas? Any help will be greatly appreciated!

4
  • 1
    Try this <link href="assets/css/globalStyles.css" rel="stylesheet" runat="server"/> As your assets folder is a parent folder and is present at the parent level. Let me know if this works Commented Feb 20, 2014 at 3:58
  • ^^ this doesnt work Mr Rohan. My default.aspx needs to access the CSS file which is outside its parent folder MasterPages. There are two folders inside my project, one is assets(contains my CSS file) and another one is MasterPages(contains Default.aspx). Thanks! Commented Feb 20, 2014 at 4:03
  • 1
    If thats the case try <link href="../assets/css/globalStyles.css" rel="stylesheet" runat="server"/> This would make the compiler search for the assets folder Outside your MasterPage folder. Commented Feb 20, 2014 at 4:09
  • I used to use ... but I want to replace it with ~ since not doing so generates an error when it's deployed in IIS. Thanks! Commented Feb 20, 2014 at 4:17

2 Answers 2

2

You have to resolve the path "~/assets/css/globalStyles.css" using Page.ResolveUrl (WebForms) or Url.Content (MVC) - so your Alt 3 must work. Look at the page html through browser's "View source" - what is href there?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Mr Igor! I reinserted my Alt 3 to see what was wrong. For some weird reason, omitting the runat="server" fixed the issue! Thanks for letting me know that my Alt 3 was indeed correct! Thank you!
1

Either -> Url.Content("~/assets/css/globalStyles.css") Or you can directly use -> href="/assets/css/globalStyles.css"

Comments

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.