John Livermore
John Livermore

Reputation: 31313

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!

Upvotes: 9

Views: 8833

Answers (5)

Dave Dunford
Dave Dunford

Reputation: 21

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.

Upvotes: 2

NightOwl888
NightOwl888

Reputation: 56859

I had this problem too, and none of the solutions here (or anywhere else that I could find) helped.

The Solution

It turned out that my CSS files were downloaded from an external source in zip format. The files were copied and pasted from the zip file to my IIS directory using Windows Explorer. If you unzip the file first before doing the copy operation, then it won't mess up the permissions and you will be able to view them in IIS.

Upvotes: 1

John Livermore
John Livermore

Reputation: 31313

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.

Upvotes: 13

Steve
Steve

Reputation: 2997

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.

Upvotes: 4

Hector Correa
Hector Correa

Reputation: 26690

As @Mike said, I am almost willing to bet that the problem is that the path to the CSS file is different when you run local than when you run on the server.

Where are your CSS files located at?

For example, if your root IIS folder is c:\inetpub\wwwroot...are your CSS files under

  • c:\inetpub\wwwroot\somefolder\content\style.css or under
  • c:\inetpub\wwwroot\content\style.css

?

Upvotes: 1

Related Questions