加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 09:25:44 所属栏目:asp.Net 来源:网络整理
导读:情况是我希望所有文件类型都由指定的dll处理,除了’aspx’文件. 但我不知道如何编辑配置文件.如下: system.web httpHandlers add verb="*" path="*" type="My.Handler" / /httpHandlers/system.web 所有请求都将由My.Handler处理.如何正常访问aspx文件? 解
情况是我希望所有文件类型都由指定的dll处理,除了’aspx’文件.

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

<system.web>
    <httpHandlers>
         <add verb="*" path="*" type="My.Handler" />
    </httpHandlers>
</system.web>

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

解决方法

我有一个“解决方法”,但它有点“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; }
    }
  }

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

<system.webServer>
     <handlers>
       <add verb="*" path="*.aspx"
        name="PassThroughAspxHandler"
        type="YourNameSpaceHere.PassThroughAspxHandler"/>
     </handlers>
   </system.webServer>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读