我的应用程序中有一个HttpModule,它使用以下代码挂钩到FormsAuthenticationModule的Authenticate事件:

public void Init(HttpApplication context)
{
    FormsAuthenticationModule faModule =
        (FormsAuthenticationModule)context.Modules["FormsAuthentication"];
    faModule.Authenticate +=
        new FormsAuthenticationEventHandler(faModule_Authenticate);
}

不幸的是,对context.Modules的调用失败了,因为应用程序需要在中等信任环境中运行。还有其他方法可以加入这个事件吗?

有帮助吗?

解决方案

这是一个艰难的 - 你甚至无法从全局应用程序文件中访问Modules集合。

您可以尝试从Global:

中的AuthenticateRequest处理程序调用自定义代码
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
    // Call your module's code here..
}

您也无法从集合中获取自定义模块,因此您需要对模块库的静态引用。

除了授予AspNetHostingPermission(详细了解其他权限)在机器级别web.config中访问您的站点,我没有想法!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top