ASP.NET MVC PostAuthorizeRequest(和其他事件)未触发
我正在开发 mvcForum 项目(在 codeplex 上),并希望从 global.asax 文件中删除尽可能多的代码 - 主要是为了更轻松地将 mvcForum 集成到现有 ASP.NET MVC 应用程序中,而无需更改太多代码。
我需要挂钩应用程序事件才能设置正确的 CultureInfo (取决于用户的选择等)和其他内容。
这在 global.asax 文件中不是问题:
protected void Application_PostAuthorizeRequest() {
// Some code here!
}
但是当我尝试将代码移到其他地方时,该事件永远不会发生。 我正在做的是这样的:
public MVCForumBootstrapper(HttpApplication app) {
app.PostAuthorizeRequest += new EventHandler(app_PostAuthorizeRequest);
}
在 global.asax 中,
protected void Application_Start() {
var strapper = new MVCForumBootstrapper(this);
}
我希望它能以完全相同的方式工作?
我做错了什么/我错过了什么?
谢谢,斯蒂恩
I'm working on the mvcForum project (on codeplex) and want to remove as much code as possible from the global.asax file - mostly to make it easier to integrate mvcForum into existing ASP.NET MVC application without changing too much code.
I need to hook into the application events to be able to set the correct CultureInfo (depending on the users' choice etc) and other things.
This isn't a problem with this in the global.asax file:
protected void Application_PostAuthorizeRequest() {
// Some code here!
}
But when I try moving the code somewhere else, the event never happens.
What I'm doing is this:
public MVCForumBootstrapper(HttpApplication app) {
app.PostAuthorizeRequest += new EventHandler(app_PostAuthorizeRequest);
}
And this in the global.asax
protected void Application_Start() {
var strapper = new MVCForumBootstrapper(this);
}
I was kind of expecting this to work in exactly the same way?
What am I doing wrong/have I missed?
Thanks, Steen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该在 Global.asax 的
Init
方法中执行此操作。在Application_Start
中,挂钩事件太晚了:You should do this in the
Init
method of Global.asax. InApplication_Start
it's too late too hook events: