我在我的网络应用程序中使用AuthorzieAttribute进行身份验证和授权。 如何更改与控制反转原理兼容的HandleUnauthorizedRequest方法(IOC)?
public class AuthorizeUser : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
return SessionContext.GetCurrentUser() != null ? true : false;
}
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary(
new
{
returnUrl = filterContext.HttpContext.Request.Url,
Area = "",
controller = "Account",
action = "Login"
})
);
}
}
答案 0 :(得分:0)
答案:
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
filterContext.HttpContext.Response.RedirectToRoute(new { controller = "Account", action = "Login", returnUrl = filterContext.HttpContext.Request.Url });
}