情况是我希望所有文件类型都由指定的dll处理,除了’aspx’文件. 但我不知道如何编辑配置文件.如下: system.web httpHandlers add verb="*" path="*" type="My.Handler" / /httpHandlers/system.web 所有请求都将
但我不知道如何编辑配置文件.如下:
<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>
