问题
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?
来源:https://stackoverflow.com/questions/15692499/page-routing-in-asp-net-4-0-extensionless-url-versus-pagehandlerfactory-asp