我想检查用户登录的身份验证并重定向到控制器涉及。
如何在此块中重定向代码?或者针对这种情况有其他解决方案吗?
对不起我的英语。
<!-- language-all: c# -->
protected override IAsyncResult BeginExecute(System.Web.Routing.RequestContext requestContext, AsyncCallback callback, object state)
{
if (requestContext.HttpContext.Request.IsAuthenticated)
{
if (Roles.IsUserInRole(requestContext.HttpContext.Request.LogonUserIdentity.Name, "Admin"))
{
//if user login is Admin redirect to Admin Controller here
}
}
return base.BeginExecute(requestContext, callback, state);
}
答案 0 :(得分:1)
我找到了解决方案。
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
if (filterContext.RequestContext.HttpContext.Request.IsAuthenticated)
{
if (Roles.IsUserInRole(User.Identity.Name, "Admin"))
{
filterContext.Result = RedirectToAction("Index", "Admin");
}
}
base.OnActionExecuted(filterContext);
}