ASP.NET page is not loading CSS styles
The stylesheets included in your master page are using relative paths.
Specify your stylesheet links with runat=server
and prefix them with the virtual web root path (~
):
<link href="~/Styles/style.css" rel="stylesheet" type="text/css" media="screen" runat="server" />
OR:
<link href="/Styles/style.css" rel="stylesheet" type="text/css" media="screen" runat="server" />
But keep in mind that the first option is recommended. The second will not work when you publish your site in a virtual directory.
After last comment...
The image URL's in CSSs should be updated as well, in order to not use relative paths or do any path traversal (../).
background: #fff url(images/img01.jpg) repeat-x left top;
For this option you will need to move the images folder inside the Styles folder (it's a good practice to do so).
Final update:
Looks like that the head
element also needs to be runat=server
in order for ASP.NET relative paths (~) to work within link
elements with runat=server
.
StyleSheet not working properly in ASP.NET
I think the problem is with path of your CSS files. If Styles folder is located in the root of your web site. add a "/" to start of css file path. like this:
<link href="/Styles/StyleSheet.css" rel="stylesheet" type="text/css" />
The above sample says: There is a Styles folder in root of my web site and inside that there is a file named StyleSheet.css
But in your sample it says: There is a Styles folder (Not in root) inside current directory (based on current URL).
So with url like this:
http://localhost/Admin/Users/Manage.aspx
It will search for css file in this address:
http://localhost/Admin/Users/Styles/StyleSheet.css
but adding a slash to start of css address may solve this problem.
UPDATE:
Check if Styles folder is a secured folder or not. Try entering css file path into your browser and if you were redirected to your login page, put a Web.Config file in your Styles directory with this content:
<configuration>
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</configuration>
ASP.net page not loading CSS with error Failed to Load Resource
Check your paths -- you may need to use a relative path instead of an absolute. Also, confirm that you can navigate to the css and js files from your browser using the path that you see in the console (you probably will not). Finally, check your IIS settings and make sure you can server Static files.
CSS not loading up in ASP.NET site when using view in browser
Are you sure it's not loading it? A few ideas:
Clear your browser cache.
Look at your IIS log file to see if those files are being requested.
Use Fiddler or FireBug to see the HTTP requests and responses.
Is that the ASP source or output HTML you posted above? If it's the ASP, check the actual output HTML.
Check that the adplayer subdirectory on the web server is accessible to the IIS process user, anonymous user or whatever.
This is a long shot, but since those files should be served by IIS not ASP, check that there is nothing in your config that is forcing them into ASP, such as:
<system.web>
<httpHandlers>
<add verb="*" path="*.js"
type="System.Web.HttpForbiddenHandler" />
</httpHandlers>
</system.web>
CSS not loading
I have seen this issue a lot in web development and there seems to be no solution as far as I know. Even sites like YouTube and gmail will sometimes not load the CSS leading to the page being rendered in a jumbled fashion with a white background. If it seems to only happen on your site, try switching hosts; maybe that will help.
Good luck!
Edit: the only reason I don't think this is code related is because you said it happens intermittently. Have you tried testing on numerous machines, not just different browsers?
Related Topics
How to Add Js and CSS Files in ASP.NET Core
How to Call a R Statistics Function to Optimize C# Function
Webexception How to Get Whole Response with a Body
Auto-Implemented Getters and Setters VS. Public Fields
Raise Event in High Resolution Interval/Timer
Linq to SQL: Multiple Joins on Multiple Columns. Is This Possible
How to Filter Directory.Enumeratefiles with Multiple Criteria
ASP.NET Core 2.0-2.2 Kestrel Not Serving Static Content
What Is a Dynamic Language, and Why Doesn't C# Qualify
Making a Private Method Public to Unit Test It...Good Idea
What's the Difference Between System.Type and System.Runtimetype in C#