在asp.net web.config中,如何配置httphandlers?

roa*_*oul 3 asp.net web-config httphandler

情况是我希望除“ aspx”文件之外的所有文件类型都由指定的dll处理。

但是我不知道如何编辑配置文件。如下:

<system.web>
    <httpHandlers>
         <add verb="*" path="*" type="My.Handler" />
    </httpHandlers>
</system.web>
Run Code Online (Sandbox Code Playgroud)

所有请求将由My.Handler处理。如何使aspx文件正常访问?

小智 5

我有一个“变通办法”,但是有点“ hacky”(我也只在本地进行了测试)...


1.创建下面的类:

public class PassThroughAspxHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
      var pageInstance = PageParser.GetCompiledPageInstance(context.Request.AppRelativeCurrentExecutionFilePath, 
                                                            context.Request.PhysicalApplicationPath + context.Request.Path, 
                                                            context);
      pageInstance.ProcessRequest(context);
    }


    public bool IsReusable
    {
      get { return false; }
    }
  }
Run Code Online (Sandbox Code Playgroud)

2.将条目添加到下面的Web配置中:( 此部分用于IIS7集成应用程序池,如果您使用的是经典应用程序池,则将有所不同):

 <system.webServer>
     <handlers>
       <add verb="*" path="*.aspx"
        name="PassThroughAspxHandler"
        type="YourNameSpaceHere.PassThroughAspxHandler"/>
     </handlers>
   </system.webServer>
Run Code Online (Sandbox Code Playgroud)