Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC3 IIS can't get stylesheets to load

I am having trouble getting my local II7 to load stylesheets when running a default 'File/New' MVC3 website. When I run the site using Visual Studio everything works great. I created an IIS7 website pointed to the root folder of the MVC website. The site comes up, but no stylesheets load. My app pool is set for .NET 4 and Integrated mode.

The same issue was described in this topic, but the fix didn't help me (I already have the 'serve static content' setting checked).

ASP.Net MVC & Local IIS Issue Loading Stylesheets

Any direction is appreciated!

like image 787
John Livermore Avatar asked Sep 07 '11 13:09

John Livermore


3 Answers

This was solved by enabling Anonymous Authentication in IIS, then right-clicking that node and choosing Edit and choosing Application Pool Identity. Everything loads correctly now. With fiddler I noticed I was getting 401 errors on the stylesheets/js files, so I knew I had a security issue.

like image 53
John Livermore Avatar answered Nov 15 '22 20:11

John Livermore


In your layout page have the style sheet like:

<link href="@Url.Content("~/folder/style.css")" type="text/css" rel="stylesheet" />

This should help by making it relative to your applications root the @Url(Content("~/ part.

like image 32
Steve Avatar answered Nov 15 '22 19:11

Steve


Another thing to check is that Static Content is enabled in Windows Features - this catches me out every time. In Windows 7:

  1. Open Control Panel
  2. Select Programs > Programs and Features > Turn Windows features on or off
  3. Expand Internet Information Services > World Wide Web Services > Common HTTP Features
  4. Check "Static Content"
  5. Click OK and wait before retrying.
like image 44
Dave Dunford Avatar answered Nov 15 '22 21:11

Dave Dunford