【问题标题】:How can I hook into the current FormsAuthenticationModule in a Medium Trust environment?如何在中等信任环境中连接到当前的 FormsAuthenticationModule?
【发布时间】:2010-09-30 16:56:32
【问题描述】:

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

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

很遗憾,对 context.Modules 的调用失败,因为应用需要在中等信任环境中运行。还有其他方法可以让我参与此活动吗?

【问题讨论】:

    标签: asp.net events forms-authentication httpmodule medium-trust


    【解决方案1】:

    这很难——您甚至无法从全局应用程序文件中访问 Modules 集合。

    您可以尝试从 Global 中的 AuthenticateRequest 处理程序调用您的自定义代码:

    protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {
        // Call your module's code here..
    }
    

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

    除了在机器级别的 web.config 中将 AspNetHostingPermission (as detailed for other permissions here) 授予您的站点之外,我没有想法!

    【讨论】:

    • 如果通过Reflector查看System.Web中HttpApplication类中的Modules属性,可以看到CAS对High trust level的需求。不幸的是,我知道我的主持人对以下问题的回答:“我们有这些很棒的 VPS/专用服务器!” :(
    • 是的,锁定托管是个问题 - 我猜你的模块是第 3 方?
    • 不,它是我自己的,所以我可以把代码放在别的地方,只是希望能把它分开。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 2011-09-17
    • 1970-01-01
    • 1970-01-01
    • 2010-10-22
    • 1970-01-01
    相关资源
    最近更新 更多