gpt4 book ai didi

security - 在 IRouteHandler.GetHttpHandler() 我可以重定向吗?

转载 作者:行者123 更新时间:2023-12-01 01:38:18 24 4
gpt4 key购买 nike

作为对未经证实的性感技巧的贪食者,我采用了 System.Web.Routing在我的 Web 窗体应用程序中管理导航等。此外,我希望将基于角色的安全性从 web.config 移动到路由定义本身,以便我可以说“此路由仅适用于角色 x、y”。

所以我得到了实现 IRouteHandler 的类,在它尝试加载特定页面之前,它会检查用户是否在其允许的角色集中。我的问题是,如果不是,我如何重定向到该处理程序中的登录页面?我知道在这种情况下可以加载登录页面,但我更喜欢使用“返回”页面和所有内容进行干净的重定向。

public IHttpHandler GetHttpHandler(RequestContext requestContext) {

if ( AllowedRoles != null )
{
bool allowed = false;

for ( int i = 0; i < AllowedRoles.Length; i++ )
{
if ( requestContext.HttpContext.User.IsInRole( AllowedRoles[i] ) )
{
allowed = true;
break;
}
}

if ( !allowed )
{
???
}
}

最佳答案

可以从 GetHttpHandler 进行重定向。只需使用:

requestContext.HttpContext.Response.Redirect("login.aspx");

关于security - 在 IRouteHandler.GetHttpHandler() 我可以重定向吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/351354/

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