代码之家  ›  专栏  ›  技术社区  ›  Greg Hurlman

如何在中等信任环境中连接到当前的FormsAuthentication模块?

  •  3
  • Greg Hurlman  · 技术社区  · 16 年前

    我的应用程序中有一个httpmodule,它用以下代码钩住FormsAuthenticationModule的authenticate事件:

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

    不幸的是,对context.modules的调用失败,因为应用程序需要在中等信任环境中运行。有没有其他方法可以让我参与这个活动?

    1 回复  |  直到 16 年前
        1
  •  3
  •   Jarrod Dixon IndianaJones    16 年前

    这是一个困难的-您甚至不能从您的全局应用程序文件中访问模块集合。

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

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

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

    除了授予AspNetHostingPermission( as detailed for other permissions here )在机器级web.config中访问您的站点,我没有主意了!