gpt4 book ai didi

c# - 每次加载页面时调用自定义 UrlAuthorization 模块

转载 作者:行者123 更新时间:2023-12-03 23:16:39 25 4
gpt4 key购买 nike

我已经实现了一个自定义 UrlAuthorization 模块,如图 here

代码如下:

public class CustomUrlAuthorizationModule : IHttpModule 
{
public void Init(HttpApplication context)
{
context.AuthorizeRequest += new EventHandler(context_AuthorizeRequest);
}



void context_AuthorizeRequest(object sender, EventArgs e)
{
HttpApplication context = (HttpApplication)sender;

if (context.User != null && context.User.Identity.IsAuthenticated)
{
HttpContext _httpContext = context.Context;
SiteMapNode node = SiteMap.Provider.FindSiteMapNode(_httpContext);
if (node == null)
throw new UnauthorizedAccessException();


}
}

public void Dispose()
{
}

}

我的问题是,我是否必须在加载时从每个页面中调用 init,或者是否有办法设置 IIS 在每次加载时自动执行此操作。

这个问题可能很愚蠢......

最佳答案

您必须在 web.config 中连接该模块。例如:

<configuration>
<system.web>
<httpModules>
<add type=
"MattsStuff.CustomUrlAuthorizationModule, MattsStuff"
name="CustomUrlAuthorizationModule" />
</httpModules>
</system.web>
</configuration>

关于c# - 每次加载页面时调用自定义 UrlAuthorization 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1575509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com