Page routing in asp.net 4.0 (extensionless url) versus PageHandlerFactory (*.aspx)

淺唱寂寞╮ 提交于 2019-12-22 10:49:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!