Requests for my css, js, image files are being served through the ASP.NET pipeline. I thought IIS by default avoided this, but I see the requests on my Application_AuthenticateRequest
breakpoint and there's no need to actually authenticate those requests. I've seen conflicting approaches to change this behavior - What is the best way to do this?
请求我的css, js,图像文件正在通过ASP服务。净管道。我认为IIS在默认情况下避免了这种情况,但是我看到了我的Application_AuthenticateRequest断点上的请求,因此不需要对这些请求进行真正的身份验证。我已经看到了改变这种行为的相互冲突的方法——最好的方法是什么?
4 个解决方案
#1
34
I'm taking a guess here and suspect that you have the following setting configured in your web.config
file:
我在这里进行猜测,并怀疑您在web中配置了以下设置。配置文件:
<modules runAllManagedModulesForAllRequests="true">
This means that every request, including those for static content is hitting the pipeline.
这意味着每个请求(包括静态内容的请求)都将到达管道。
Change this setting to:
改变这个设置:
<modules runAllManagedModulesForAllRequests="false">
This is assuming your application is running under ASP.NET 4.0 and MVC3.
这是假设您的应用程序在ASP下运行。NET 4.0和MVC3。
For this to work you need to install KB980368 (requires a reboot) or Windows 2008R2 SP1 (which includes this hotfix). The reason for this is explained in this excellent article:
要实现这一点,您需要安装KB980368(需要重新启动)或Windows 2008R2 SP1(包括此热修复)。原因在这篇优秀的文章中得到了解释:
How ASP.NET MVC Routing Works and its Impact on the Performance of Static Requests
ASP。NET MVC路由工作及其对静态请求性能的影响。
#2
12
I ended up adding this to my web.config. I know all my static files will exist in these folders, so it works ok for my needs.
最后我把它添加到我的web.config中。我知道我所有的静态文件都将存在于这些文件夹中,所以它可以满足我的需要。
<location path="scripts">
<system.web>
<authentication mode="None" />
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="styles">
<system.web>
<authentication mode="None" />
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="images">
<system.web>
<authentication mode="None" />
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
#3
1
In VS2012 /MVC3 with the Visual Studio Development Server enabled, the RAMMFAR=false has no effect. Each request for static files still hits the Application_BeginRequest event handler.
在启用Visual Studio开发服务器的VS2012 /MVC3中,RAMMFAR=false没有效果。对静态文件的每个请求仍然会访问Application_BeginRequest事件处理程序。
I switched over to IIS Express and saw the desired functionality.
我切换到IIS Express,看到了所需的功能。
#4
0
Somewhere in either your IIS configuration, or a web.config, you have a handler mapping set up to map these files to your ASP.Net application.
在IIS配置或web中的某个位置。配置,您已经设置了一个处理程序映射来将这些文件映射到您的ASP。网络应用程序。
Try deleting your web.config and see if you can still browse to these file types from within IIS without ASP.Net. If that fails you'll know it's your web.config - otherwise you'll have to check the IIS settings.
尝试删除您的web。配置并查看是否仍然可以在没有ASP.Net的情况下从IIS中浏览这些文件类型。如果失败了,你会知道这是你的网络。配置-否则你必须检查IIS设置。
Step 2 - Put the web.configs back, then delete and recreate the site - same problem? It's a setting in the root of IIS which means it applies to all sites - check the handler mappings here.
第2步-建立网络。配置返回,然后删除和重新创建站点——同样的问题?它是IIS根目录中的一个设置,这意味着它适用于所有站点——请查看这里的处理程序映射。
#1
34
I'm taking a guess here and suspect that you have the following setting configured in your web.config
file:
我在这里进行猜测,并怀疑您在web中配置了以下设置。配置文件:
<modules runAllManagedModulesForAllRequests="true">
This means that every request, including those for static content is hitting the pipeline.
这意味着每个请求(包括静态内容的请求)都将到达管道。
Change this setting to:
改变这个设置:
<modules runAllManagedModulesForAllRequests="false">
This is assuming your application is running under ASP.NET 4.0 and MVC3.
这是假设您的应用程序在ASP下运行。NET 4.0和MVC3。
For this to work you need to install KB980368 (requires a reboot) or Windows 2008R2 SP1 (which includes this hotfix). The reason for this is explained in this excellent article:
要实现这一点,您需要安装KB980368(需要重新启动)或Windows 2008R2 SP1(包括此热修复)。原因在这篇优秀的文章中得到了解释:
How ASP.NET MVC Routing Works and its Impact on the Performance of Static Requests
ASP。NET MVC路由工作及其对静态请求性能的影响。
#2
12
I ended up adding this to my web.config. I know all my static files will exist in these folders, so it works ok for my needs.
最后我把它添加到我的web.config中。我知道我所有的静态文件都将存在于这些文件夹中,所以它可以满足我的需要。
<location path="scripts">
<system.web>
<authentication mode="None" />
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="styles">
<system.web>
<authentication mode="None" />
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="images">
<system.web>
<authentication mode="None" />
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
#3
1
In VS2012 /MVC3 with the Visual Studio Development Server enabled, the RAMMFAR=false has no effect. Each request for static files still hits the Application_BeginRequest event handler.
在启用Visual Studio开发服务器的VS2012 /MVC3中,RAMMFAR=false没有效果。对静态文件的每个请求仍然会访问Application_BeginRequest事件处理程序。
I switched over to IIS Express and saw the desired functionality.
我切换到IIS Express,看到了所需的功能。
#4
0
Somewhere in either your IIS configuration, or a web.config, you have a handler mapping set up to map these files to your ASP.Net application.
在IIS配置或web中的某个位置。配置,您已经设置了一个处理程序映射来将这些文件映射到您的ASP。网络应用程序。
Try deleting your web.config and see if you can still browse to these file types from within IIS without ASP.Net. If that fails you'll know it's your web.config - otherwise you'll have to check the IIS settings.
尝试删除您的web。配置并查看是否仍然可以在没有ASP.Net的情况下从IIS中浏览这些文件类型。如果失败了,你会知道这是你的网络。配置-否则你必须检查IIS设置。
Step 2 - Put the web.configs back, then delete and recreate the site - same problem? It's a setting in the root of IIS which means it applies to all sites - check the handler mappings here.
第2步-建立网络。配置返回,然后删除和重新创建站点——同样的问题?它是IIS根目录中的一个设置,这意味着它适用于所有站点——请查看这里的处理程序映射。