简体   繁体   中英

Absolute paths for CSS files in ASP.net

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!

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?

-> Url.Content(“〜/ assets / css / globalStyles.css”)或直接使用-> href =“ / assets / css / globalStyles.css”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM