另类的地方注册航线的Global.asax [英] Alternative places to register routes to global.asax
问题描述
这是最常见的做法是的global.asax.cs / VB
文件中注册在Application_Start事件的路线。但是,你需要有访问此文件这样做。精细。
It's most common practice to register routes in Application_Start event within global.asax.cs/vb
file. But you need to have access to this file to do so. Fine.
我要么没有或不想。我想Asp.net MVC应用程序集成到SharePoint 2010网站,并且不希望创建我的自定义全球应用类,这也将注册路线我和改变SharePoint的Global.asax文件,并把不同的类定义它。我的应用程序将不会被接受,因为我会做的事不支持到SharePoint。
I either don't have or don't want to. I'm trying to integrate Asp.net MVC application into a Sharepoint 2010 site and don't want to create my custom global application class that would also register routes for me and change the Sharepoint's Global.asax file and put a different class definition in it. My application wouldn't be accepted because I would be doing unsupported things to Sharepoint.
我想知道是否有可能注册路线别的地方呢?有迹象表明,第一个出现在我脑海两种选择:
I was wondering if it was possible to register routes some place else then? There are two alternatives that first popped into my mind:
-
<击> 写一个HttpModule 和滥用的应用程序启动事件为好。这样,我会的注入的应用程序启动事件code而不Global.asax的,我不能进入重整。添加在web.config中另一个HTTP模块是我能做到的。击>
Write an HttpModule and abuse application start event as well. This way I would inject application start event code without mangling with global.asax that I can't access. Adding another HttpModule in web.config is something I can do.
注意:应用程序级别的事件不是模块访问。无赖。他们只能访问请求级事件。
Note: Application-level events are not accessible in modules. Bummer. They can only access request-level events.
重要: ...我这样想着。如果你选择接受的答案,它实际上能够处理应用程序级的启动事件。间接且可靠它是可能的。
Important: ... or so I thought. If you check accepted answer it's actually possible to handle application-level start event. Indirectly and reliably it is possible.
写一个HttpModule 和滥用的其他一些事件例如请求启动即可。当然,我也有保留一些数据somewehere,我的路线已经注册和登记,会发生仅在第一次圆的。
Write an HttpModule and abuse some other event like request start. Of course I would also have to keep some data somewehere that my routes have already been registered and that registration would happen only the first time round.
是否有任何更好的方法/地方注册路线?
推荐答案
如果你检查我的的其他问题你会看到,这是容易做到。我后来做了,我可以向你保证,它的工作原理。
Catching Application Start event in an HttpModule is possible
If you check my other question you will see this is easily possible. I've done it afterwards and I can assure you it works.
我也博客上讲述这个的功能的...两次:
I've also blogged about this feature... Twice:
- Writing a custom
IHttpModule
that handlesApplication_OnStart
event - How to correctly use
IHttpModule
to handleApplication_OnStart
event
这篇关于另类的地方注册航线的Global.asax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!