4

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

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

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 )
    {
        ???
    }
}
4

1 回答 1

4

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

requestContext.HttpContext.Response.Redirect("login.aspx");
于 2009-01-25T22:15:56.710 回答