我想写一个 IHttpModule
必须严格执行 FormsAuthenticationModule
否则就没用了。
有 HttpContext.Current.ApplicationInstance.Modules
返回集合的属性 IHttpModule
秒。我可以检查我的模块是否已经完成 FormsAuthenticationModule
在这个集合中。
这还够吗?那个收藏清单 IHttpModule
s按执行顺序排列?
我想写一个 IHttpModule
必须严格执行 FormsAuthenticationModule
否则就没用了。
有 HttpContext.Current.ApplicationInstance.Modules
返回集合的属性 IHttpModule
秒。我可以检查我的模块是否已经完成 FormsAuthenticationModule
在这个集合中。
这还够吗?那个收藏清单 IHttpModule
s按执行顺序排列?
回想一下,模块可以订阅不同的管道事件。在任何给定的管道事件中,模块应按照在Modules集合中指定的顺序运行。
作为一个实际的例子,设想一个模块集合,它注册了这三个模块:
执行顺序如下:
由于FormsAuthenticationModule订阅了AuthenticateRequest事件,因此请考虑让您自己的模块订阅PostAuthenticateRequest事件。这样就可以保证,如果FormsAuthenticationModule逻辑运行,它就会运行 在你的逻辑之前,无论他们在Modules系列中注册的顺序如何。
回想一下,模块可以订阅不同的管道事件。在任何给定的管道事件中,模块应按照在Modules集合中指定的顺序运行。
作为一个实际的例子,设想一个模块集合,它注册了这三个模块:
执行顺序如下:
由于FormsAuthenticationModule订阅了AuthenticateRequest事件,因此请考虑让您自己的模块订阅PostAuthenticateRequest事件。这样就可以保证,如果FormsAuthenticationModule逻辑运行,它就会运行 在你的逻辑之前,无论他们在Modules系列中注册的顺序如何。
我会尽力回答。
我认为你不应该依赖HttpContext.Current.ApplicationInstance.Modules集合,因为你现在在执行哪个命令模块。
请注意,我没有做任何原型,这只是我的想法。
dll Microsoft.Web.Infrastructure.dll有一个动态注册HTTP模块的方法
该DLL随WebPages 1.0一起提供
创建帮助类以进行注册
public static class RegisterHttpModuleHelper
{
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(YourCustomModule));
}
}
FormsAuthenticationModule具有事件“Authenticate”。
在处理此事件时,尝试使用动态注册您的Custom HttpModule
public void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs args)
{
RegisterHttpModuleHelper.Start()
}