C# IIS 中未加载 CSS、图像、JS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10512053/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CSS, Images, JS not loading in IIS
提问by Imran Rashid
My all applications were working fine but suddenly all sites under IIS are not loading css, images, scripts. It redirect to login page.
我的所有应用程序都运行良好,但突然之间 IIS 下的所有站点都没有加载 css、图像、脚本。它重定向到登录页面。
If i login it works fine. e.g. mysite.com/Account/LogOn?ReturnUrl=%2fpublic%2fimages%2ficons%2f41.png
如果我登录它工作正常。例如 mysite.com/Account/LogOn?ReturnUrl=%2fpublic%2fimages%2ficons%2f41.png
On my local machine it works fine without login.
在我的本地机器上,它无需登录即可正常工作。
采纳答案by Imran Rashid
It was windows permission issue i move the folder thats it inherit wrong permissions. When i move to wwwroot folder and add permission to iis user it start working fine.
这是Windows权限问题,我移动了继承错误权限的文件夹。当我移动到 wwwroot 文件夹并向 iis 用户添加权限时,它开始正常工作。
回答by Tim Medora
You probably have Windows authentication enabled in your web.config. On a local machine, your Windows credentials are automatically passed and it works. On a live site, you are treated as an anonymous user (IE setting can control this, but don't modify this unless you really know what you are doing).
您可能在 web.config 中启用了 Windows 身份验证。在本地计算机上,您的 Windows 凭据会自动传递并且可以正常工作。在实时站点上,您将被视为匿名用户(IE 设置可以控制这一点,但除非您真的知道自己在做什么,否则不要修改它)。
This causes the following:
这会导致以下情况:
- You are required to explicitly login.
- Resources like scripts and CSS are not served on the login page because you are not authenticated.
- 您需要明确登录。
- 脚本和 CSS 等资源不会在登录页面上提供,因为您未经过身份验证。
This isn't broken, just working as intended, but to "fix" this:
这并没有坏,只是按预期工作,但要“修复”这个:
- Change the authentication type in the web.config if you don't want any login.
- And/or add a web.config in the directory(s) containing CSS, images, scripts, etc. which specifies authorization rules.
- 如果您不想登录,请更改 web.config 中的身份验证类型。
- 和/或在包含指定授权规则的 CSS、图像、脚本等的目录中添加 web.config。
回答by Mathias F
Add this to your web.config
将此添加到您的 web.config
<location path="Images">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
回答by Rohit Vyas
Use this in configuration section of your web.config file:
在 web.config 文件的配置部分使用它:
<location path="images">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="css">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="js">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
回答by user23462
This might not answer your question but I've been banging my head with the same symptoms with a new IIS installation. CSS, JS and images were not showing up. Was due to the "Static Content" role not being installed in IIS 7.5.
这可能无法回答您的问题,但我一直在用新的 IIS 安装遇到相同的症状。CSS、JS 和图像没有显示出来。是由于未在 IIS 7.5 中安装“静态内容”角色。
回答by Matt Kocaj
The problem may be that IIS is not serving Static Content, which you can set up here:

问题可能是 IIS 不提供静态内容,您可以在此处设置:

Source: http://adilmughal.com/blog/2011/11/iis-7-not-loading-css-and-image/
来源:http: //adilmughal.com/blog/2011/11/iis-7-not-loading-css-and-image/
Windows 10:
视窗 10:
回答by Moiz Tankiwala
I had the same problem, an unauthenticated page would not load the CSS, JS and Images when I installed my web application in ASP.Net 4.5 in IIS 8.5 on Windows Server 2012 R2.
我遇到了同样的问题,当我在 Windows Server 2012 R2 上的 IIS 8.5 中的 ASP.Net 4.5 中安装我的 Web 应用程序时,未经身份验证的页面不会加载 CSS、JS 和图像。
- I had the static content role installed
- My Web Application was in the wwwroot folder of IIS and all the Windows Folder permissions were intact (the default ones, including IIS_IUSRS)
- I added authorization for all the folders that contained the CSS, JS and images.
- I had the web application folder on a windows share, so I removed the sharing as suggested by @imran-rashid
- 我安装了静态内容角色
- 我的 Web 应用程序位于 IIS 的 wwwroot 文件夹中,并且所有 Windows 文件夹权限都完好无损(默认权限,包括 IIS_IUSRS)
- 我为所有包含 CSS、JS 和图像的文件夹添加了授权。
- 我在 Windows 共享上有 Web 应用程序文件夹,所以我按照@imran-rashid 的建议删除了共享
Yet, nothing seemed to solved the problem. Then finally I tried setting the identity of the anonymous user to the App Pool Identity and it started working.
然而,似乎没有什么能解决这个问题。最后,我尝试将匿名用户的身份设置为 App Pool Identity 并开始工作。






I banged my head for a few hours and hope that this response will save the agony for my fellow developers.
我敲了几个小时的头,希望这个回复可以为我的开发人员节省痛苦。
I would really like to know why this is working. Any thoughts?
我真的很想知道为什么这是有效的。有什么想法吗?
回答by Hiep
回答by Naijalivemedia
To fix this:
要解决此问题:
Go to Internet Information Service (IIS)
转至 Internet 信息服务 (IIS)
Click on your website you are trying to load image on
单击您尝试加载图像的网站
Under IIS section, Open the Authentication menu and Enable Windows Authentication as well.
在 IIS 部分下,打开身份验证菜单并启用 Windows 身份验证。
回答by ihebiheb
For me adding this in the web.configresolved the problem
对我来说,在已web.config解决的问题中添加这个
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" >
<remove name="UrlRoutingModule"/>
</modules>
</system.webServer>

