I was wondering if there is any way to get the HttpHandler for a given path.
Something like the following:
var url = "~/MyFolder/MyFile.axd";
IHttpHandler = MagicObject.GetHandler(url);
Does that "MagicObject" exist somewhere in the .NET framework? :)
Thank you, bye.
=WereWolf= --
Helping someone does not mean giving them what they need, but making them able to get it themselves
--
The Code Golem http://www.codegolem.com/
There's no built-in tool to retrieve Handlers defined in ASP.NET unforatunately - you can get Modules, but not handlers which is kind of silly.
In fact, there's not even an easy way to even get a list of all Http handlers active at a given site or application. The process can be complicated because there are actually two sections that might apply (system.web/httpHandlers or system.webServer/handlers
in IIS 7+).
For non-integrated mode access it's possible to loop through declared handlers and you can then compare against your file spec:
Unfortunately on IIS 7 the system.web/handlers section is locked so you don't get the same type of access to that section. For IIS 7 one possibility is to loop through the defined handlers manually:
WereWolf
Contributor
2841 Points
399 Posts
How to get HttpHandler class for a given url? Please help!
Nov 04, 2011 02:01 PM|LINK
Hello there,
I was wondering if there is any way to get the HttpHandler for a given path.
Something like the following:
var url = "~/MyFolder/MyFile.axd";
IHttpHandler = MagicObject.GetHandler(url);
Does that "MagicObject" exist somewhere in the .NET framework? :)
Thank you, bye.
--
Helping someone does not mean giving them what they need, but making them able to get it themselves
--
The Code Golem http://www.codegolem.com/
rstrahl
Contributor
2233 Points
375 Posts
ASPInsiders
MVP
Re: How to get HttpHandler class for a given url? Please help!
Nov 11, 2011 12:23 AM|LINK
There's no built-in tool to retrieve Handlers defined in ASP.NET unforatunately - you can get Modules, but not handlers which is kind of silly.
In fact, there's not even an easy way to even get a list of all Http handlers active at a given site or application. The process can be complicated because there are actually two sections that might apply (system.web/httpHandlers or system.webServer/handlers in IIS 7+).
For non-integrated mode access it's possible to loop through declared handlers and you can then compare against your file spec:
Configuration cfg = WebConfigurationManager.OpenWebConfiguration("/westwindwebtoolkitweb"); ConfigurationSection cfgSection = cfg.GetSection("system.web/handlers"); var xml = cfgSection.ToString(); HttpHandlersSection handlers = (HttpHandlersSection)cfgSection; foreach(HttpHandlerAction handler in handlers.Handlers) { Response.Write( handler.Path + " - " + handler.Type + " - " + handler.Verb + "<hr/>"); }Unfortunately on IIS 7 the system.web/handlers section is locked so you don't get the same type of access to that section. For IIS 7 one possibility is to loop through the defined handlers manually:
Configuration cfg = WebConfigurationManager.OpenWebConfiguration("/westwindwebtoolkitweb"); ConfigurationSection cfgSection = cfg.GetSection("system.web/httpHandlers"); var xml = cfgSection.ToString(); HttpHandlersSection handlers = (HttpHandlersSection)cfgSection; foreach(HttpHandlerAction handler in handlers.Handlers) { Response.Write( handler.Path + " - " + handler.Type + " - " + handler.Verb + "<hr/>"); }But keep in mind that this will only give you the handlers defined in the current app, not the entire hierarchy up the chain like the first example.
Not exactly what you're looking for but maybe this points you in the right direction...
+++ Rick ---
West Wind Technologies
Making waves on the Web
www.west-wind.com/weblog
CyrilCS
Contributor
6465 Points
23 Posts
Re: How to get HttpHandler class for a given url? Please help!
May 23, 2012 12:13 PM|LINK
Hi,
I was just having the same requirement. For thoses who are interested in the answer, you can use :
BuildManager.CreateInstanceFromVirtualPath("~/pouet.aspx", typeof(Page))