开发者

Adding a custom httpmodule to route to MVC or custom handler selectively

I'm not sure if this has been asked already. Well, here is my problem.

I have a classic Web Forms site that I'm trying to turn into hybrid-MVC. That is, all new functionality would be MVC. However, we have a custom HTTP handler that takes care of our 开发者_Go百科darn-friendly URLs and which we are not planning on changing. My problem right now is adding our existing urls as ignore routes. I do not want to add all (the 1000s) of them as exceptions in the Application_Start(). Adding a custom http module that would site on top of MVC and our existing custom handler seemed to be a feasible solution. This module would essentially route requests by checking against an XML file (of existing routes) and decide whether MVC or MyHandler would process the request.

Anybody tried this? I'm having trouble offloading the request to the appropriate handler.


The best way to accomplish this is to convert your HttpHandler into an HttpModule and make sure that all requests pass through your custom module before being handed off to MVC. Since MVC is implemented as a module, it will always intercept your requests before the reach your handler.


create a custom contraint by implementing IRouteContraint that looks in your XML file, and then pass it in to your routes when you map them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜