2014-02-27 84 views
3

这种情况是,我希望所有的文件类型都由指定的dll 来处理,除了'aspx'文件在asp.net web.config中,如何配置httphandlers?

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

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

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

+0

您是否收到任何错误? – shanish

+0

什么样的错误?没有错误。 –

+0

你真的在运行IIS6还是在经典模式? – MikeSmithDev

回答

2

只是一个猜测,但尝试了一个后加入这个你想出了:

<add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory"/> 
+0

它不起作用 –

+1

好吧,这是一个无赖 –

+0

@roast_soul定义“不起作用”。因为你导航到“/”,它没有工作吗?如果导航到“/default.aspx”,会发生什么情况? – MikeSmithDev

4

我有“解决”,但它是一种“哈克”(我只测试它在本地以及)...


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> 
1

试试这个,添加一些对罗伯特的职位

<add verb="*" path="*.aspx" type="Your handler class name"/> 

this link