Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In asp.net web.config, how to config the httphandlers?

The situation is that I want all the file types to be handled by a specified dll except 'aspx' file.

But I don't know how to edit the configuration file. As below:

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

All the requests will be handled by My.Handler. How to make the aspx file be accessed normally?

like image 856
roast_soul Avatar asked Dec 18 '25 13:12

roast_soul


2 Answers

I have a "work around", but it's kind of "hacky" (and I only tested it locally as well)...


1. Create the class below:

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. Add the entry to your web config below: (this part is for IIS7 integrated app pools, it will be slightly different if you are using a classic app pool):

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

Just a guess but try adding this after the one you came up with:

<add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory"/>
like image 33
Robert Levy Avatar answered Dec 20 '25 06:12

Robert Levy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!