webforms - Asp.Net not using the handler resolved in PageHandlerFactory -
i trying intercept calling of pages in asp.net, can change object before used.
providing simplified code, illustrate problem.
debugging, step custompagehandlerfactory, , see using base method instance of page. instance not seem passed forward.
hashcode of gethandler's object , instance's hashcode of page differ.
shouldn't same?
the page:
public partial class _default : page { public bool throw { get; set; } public _default() { throw = true; } protected void page_load(object sender, eventargs e) { throwexception(); } public virtual void throwexception() { if (throw) { throw new exception("non sense error!"); } } }
the handlerfactory:
public class custompagehandlerfactory : pagehandlerfactory { public override ihttphandler gethandler(httpcontext context, string requesttype, string virtualpath, string path) { var page = base.gethandler(context, requesttype, virtualpath, path); ((_default)page).throw = false; return page; } }
and chunk of config:
(...) <system.webserver> <handlers> <add name="custompagehandler" path="*.aspx" verb="*" type="example.custompagehandlerfactory" /> </handlers> <validation validateintegratedmodeconfiguration="false" /> </system.webserver> <system.web> <httphandlers> <remove verb="*" path="*.aspx" /> <add verb="*" path="*.aspx" type="example.custompagehandlerfactory" /> </httphandlers> (...)
as pointed out @ondrej svejdar, should add framework versions:
- c# 4.5
- asp.net 4.0
- iis 7.5
- visual studio 2013
Comments
Post a Comment