作为对未经验证的热门技术的狂热爱好者,我在Web Forms应用程序中采用了System.Web.Routing来管理导航等。此外,我希望将基于角色的安全性从web.config转移到路由定义本身,这样我就可以说“此路由仅对角色x,y可用”。
因此,我得到了实现IRouteHandler的类,在尝试加载特定页面之前,它会检查用户是否在它允许的角色集中。我的问题是,如果它们不是,我如何重定向到该处理程序中的登录页面?我知道在这种情况下可以加载登录页面,但我更喜欢使用“returnto to”页面的干净重定向。
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 )
{
???
}
}发布于 2009-01-25 22:15:57
从GetHttpHandler进行重定向是可能的。只需使用:
requestContext.HttpContext.Response.Redirect("login.aspx");https://stackoverflow.com/questions/351354
复制相似问题