3

Explain me please, how these two techniques differs. I assume, based on my experience described below and this article, that when routing is applied, PageHandlerFactory is not called.

I have my own class derived from PageHandlerFactory that should be called whenever a user access a page.

When I don't access pages through routes, everything is just fine with this line of code in web.config

<httpHandlers>
      <add verb="*" path="*.aspx" type="MyProject.Web.DependencyInjectionPageHandlerFactory, MyProject.Web" />
    </httpHandlers>

But when I access a page through a route, e.g.

RouteTable.Routes.MapPageRoute("Login", "login", "~/Pages/Login.aspx");

the handler is not applied. I even tested it by putting a breakpoint into the constructor of my handler and it wasn't invoked when I accessed a page through a route. Since I'm using IoC/DI in my project, I would like continue using it to inject DI into my aspx pages even if I'm using routing.

How would I manage this in the web.config? Or at least in code.


EDIT: I found out that there is the event raised every time a page is loading, no matter how. In Global.asax it is

Application_PostRequestHandlerExecute

Now, I can easily tell, how it is called by parsing URL. Is there a way, how to apply my PageHandlerFactory on some pages?

Ondrej Janacek
  • 12,486
  • 14
  • 59
  • 93
  • Looks like the default RouteHandler picked up in this case and used it's own pipeline to handle the page creation. If you want to do this you should not restrict your handle to .aspx pages. – tucaz Mar 28 '13 at 22:06
  • Ok, what is the correct expression for the path? – Ondrej Janacek Mar 29 '13 at 08:48

0 Answers0