对静态文件的请求被击中ASP.NET MVC3托管code [英] Requests for static files are hitting the managed code in ASP.NET MVC3

查看:222
本文介绍了对静态文件的请求被击中ASP.NET MVC3托管code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建自定义IHttpModules,我已经意识到,对静态文件的要求(例如:.css和.js文件)均创下的管理模块。图片可能有同样的问题。应该没有文件绕过IIS ASP.NET中存在的文件系统?

例如:

 公共类MyModule的:IHttpModule的
{
    公共无效的Dispose(){}    公共无效初始化(HttpApplication的情况下)
    {
        context.BeginRequest + =(O,E)=> Debug.Print(请求:+ HttpContext.Current.Request.RawUrl);
    }
}

和我宣布这样说:

 <模块runAllManagedModulesForAllRequests =真正的>
  <添加名称=MyModule的preCondition =managedHandlerTYPE =MVCX.Modules.MyModule,MVCX/>
< /模块>

但是,即便是使用precondition我能看到静态文件如何去通过模块:

 请求:/ MVCX /
要求:/MVCX/Content/Site.css
要求:/MVCX/Scripts/jquery-1.4.4.min.js

我试图忽略静态文件的规则,但它不会有所作为:

  routes.IgnoreRoute({内容} / {*} PATHINFO);
routes.IgnoreRoute({脚本} / {*} PATHINFO);

这是通常的?还是我失去了一些东西在这里?据我所知,如果静态文件请求应该由IIS回答。如果我的管理模块被击中,意味着一个CLR线程池线程处理该请求,对吧?

问候。

更新:

我禁用了runAllManagedModulesForAllRequests

 <模块runAllManagedModulesForAllRequests =false的>
      <添加名称=MyModule的preCondition =managedHandlerTYPE =MVCX.Modules.MyModule,MVCX/>
< /模块>

和一切似乎都工作得很好,但我发现这篇文章:<一href=\"http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html\">http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html该建议捞出用一个空precondition重新进行添加了UrlRoutingModule-4.0模块。

我的机器,该模块的加入是在根web.config,它已经空preCondition:

  C:\\ WINDOWS \\ Microsoft.NET \\ Framework64 \\ v4.0.30319 \\ Config中&GT;类型的machine.config |找到UrlRouting
C:\\ WINDOWS \\ Microsoft.NET \\ Framework64 \\ v4.0.30319 \\ Config中&GT;类型的web.config |找到UrlRouting
            &LT;添加名称=UrlRoutingModule-4.0TYPE =System.Web.Routing.UrlRoutingModule/&GT;C:\\ WINDOWS \\ Microsoft.NET \\ Framework64 \\ v4.0.30319 \\ Config中&GT;

所以,现在我是一个有点困惑,这是什么参数的状态?我应该使用它或不应该?为什么它默认来作为真实?

问候。


解决方案

  

我的机器,该模块的加入是在根web.config,它已经空preCondition


完美。这意味着,该模块将总是运行。这是需要MVC,因为它使用扩展名的URL。


  

所以,现在我是一个有点困惑,这是什么参数的状态?我应该使用它或不应该?为什么它默认来作为真实?


由于扩展名的URL支持是IIS7 SP1和IIS7.5 SP1新。
它可用于IIS7的,你必须申请并安装补丁。
您将完全解答您的疑问在这里找到:
http://support.microsoft.com/kb/980368

为什么这个参数默认来真的吗?因为在VS2010 SP1 IIS7出货前。
也许这是在新的MVC项目虚假VS2010SP1?

Creating custom IHttpModules, I have realized that the requests for static files (e.g.: .css and .js files) are hitting the managed modules. Probably pictures have the same problem. Shouldn't IIS bypass ASP.NET for files that exists in the filesystem?

For example:

public class MyModule:IHttpModule
{
    public void Dispose(){ }

    public void Init(HttpApplication context)
    {
        context.BeginRequest += (o, e) => Debug.Print("Request: " + HttpContext.Current.Request.RawUrl);
    }
}

And I declare it this way:

<modules runAllManagedModulesForAllRequests="true">
  <add name="MyModule" preCondition="managedHandler" type="MVCX.Modules.MyModule, MVCX"/>
</modules>

But, even using the precondition I can see how the static files goes through the module:

Request: /MVCX/
Request: /MVCX/Content/Site.css
Request: /MVCX/Scripts/jquery-1.4.4.min.js

I have tried to ignore the rules for static files, but it does not make a difference:

routes.IgnoreRoute("{Content}/{*pathInfo}");
routes.IgnoreRoute("{Scripts}/{*pathInfo}");

Is this the usual? Or am I missing something here? As far as I know, if the static file request should be answered by IIS. If my managed module is being hit, means that a CLR ThreadPool thread is handling that request, right?

Regards.

UPDATE:

I have disabled the "runAllManagedModulesForAllRequests":

<modules runAllManagedModulesForAllRequests="false">
      <add name="MyModule" preCondition="managedHandler" type="MVCX.Modules.MyModule, MVCX" />
</modules>

And everything seems to work just fine, but I have found this article: http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html that recommends remove and readd the "UrlRoutingModule-4.0" module with an empty precondition.

I my machine, the adding of that module is in the root web.config, and it has already an empty preCondition:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config>type machine.config | find "UrlRouting"


C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config>type web.config | find "UrlRouting"
            <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" />

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config>

So now I am a little bit confused, what is the status of this parameter? Should I use it or shouldn't? why does it come as "true" by default?

Regards.

解决方案

I my machine, the adding of that module is in the root web.config, and it has already an empty preCondition

Perfect. That means this module will always run which is required for MVC as it uses extensionless urls.

So now I am a little bit confused, what is the status of this parameter? Should I use it or shouldn't? why does it come as "true" by default?

Because extensionless url support is new in IIS7 SP1 and IIS7.5 SP1. It is available for IIS7 as a patch that you have to request and install. You will find it here with complete answers to your questions: http://support.microsoft.com/kb/980368

Why this parameter comes to true by default ? Because VS2010 was shipped before IIS7 SP1. Maybe it is at false in new MVC projects in VS2010SP1 ?

这篇关于对静态文件的请求被击中ASP.NET MVC3托管code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆