开发者

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

I am having trouble getting my local II7 to load stylesheets whe开发者_开发百科n 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!


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.


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.


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.


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

?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜