Trigger HttpHandler on specific URL

Vote:
 

How do I trigger a HttpHandler on a specific url? For example */external/*

The purpose is for retrieving an external document and stream out to the page.

#189523
Mar 20, 2018 14:27
Vote:
 

you would need to add some magic in web.config file:

<configuration>
  <system.webServer>
    <handlers>
      <add name="ExternalResourceHandler" 
           path="/external/*"
           verb="GET"
           type="{FQN of your HTTP handler type + assembly name}"/>
    </handlers>
  </system.webServer>
</configuration>
#189696
Mar 23, 2018 8:23
Vote:
 

I did try that but it didn't work.

Instead I had to add this:

routes.Add(new Route("external/{guid}", new ExternalRouteHandler()));

public class ExternalRouteHandler: IRouteHandler

{

         publicIHttpHandler GetHttpHandler(RequestContext requestContext)

        {

                    return new ExternalHttpHandler();

         }

}

public class ExternalHttpHandler : IHttpHandler

{

            public bool IsReusable

           {

                       get { return false; }

           }

           public void ProcessRequest(HttpContext context)

          {

                  //Your ccustom code here

          }

}

#189703
Mar 23, 2018 8:33
Vote:
 

hm, interesting. my web.config works just fine. are "run managed stuff for all requests" enabled in web.config?

btw, assume that you need to *insert* this route at the beginning and not adding that (as it might be overwritten by some epi "final not found route")?

#189719
Mar 23, 2018 10:21
Vote:
 

Yes, runAllManagedModulesForAllRequests is enabled.

I don't follow your meaning with insert and adding. :)

#189720
Mar 23, 2018 10:51
Vote:
 

guess for the routing you should be fine with just adding a route. sometimes we noticed that route is added "too late" to the route table resulting in some overwrites and route handler does not have chance to execute anymore.

#189736
Mar 23, 2018 12:23
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.