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

发布于 2024-07-11 18:32:13 字数 445 浏览 8 评论 0原文

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

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

不幸的是,对 context.Modules 的调用失败,因为应用程序需要在中等信任环境中运行。 我可以通过其他方式参与此活动吗?

I've got an HttpModule in my application that hooks into the FormsAuthenticationModule's Authenticate event with the following code:

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

Unfortunately, the call to context.Modules fails because the app needs to run in a medium-trust environment. Is there another way that I can hook into this event?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆消瘦 2024-07-18 18:32:13

这是一项艰巨的任务 - 您甚至无法从全局应用程序文件中访问模块集合。

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

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

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

除了授予 AspNetHostingPermission(此处详细介绍其他权限 )到你的网站在机器级别的 web.config 中,我没有主意了!

That's a tough one - you can't even access the Modules collection from within your Global application file.

You could try calling your custom code from the AuthenticateRequest handler in Global:

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

You can't grab your custom module from the collection, either, so you'd need a static reference to your module's library.

Other than granting the AspNetHostingPermission (as detailed for other permissions here) to your site in the machine level web.config, I'm out of ideas!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文