ASP.NET MVC PostAuthorizeRequest(和其他活动)不触发 [英] ASP.NET MVC PostAuthorizeRequest (and other events) not firing

查看:495
本文介绍了ASP.NET MVC PostAuthorizeRequest(和其他活动)不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的mvcForum项目(在codePLEX),并希望从Global.asax文件中删除尽可能多的code尽可能 - 主要是为了使其更容易mvcForum集成到现有的ASP.NET MVC应用程序而无需改变太多code。

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.

我需要挂钩到应用程序的事件,以便能够设定正确的CultureInfo(取决于用户的选择等)和其他东西。

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.

这是不是在Global.asax文件这个问题:

This isn't a problem with this in the global.asax file:

protected void Application_PostAuthorizeRequest() {
       // Some code here!
}

但是当我尝试移动code别的地方,事件从未发生过。
我在做什么是这样的:

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);
}

这在Global.asax

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?

谢谢,斯蒂恩

推荐答案

您应该在初始化的Global.asax的方式做到这一点。在的Application_Start 为时已晚太勾事件:

You should do this in the Init method of Global.asax. In Application_Start it's too late too hook events:

public override void Init()
{
    base.Init();
    var strapper = new MVCForumBootstrapper(this);
}

这篇关于ASP.NET MVC PostAuthorizeRequest(和其他活动)不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆