解决此问题的一个好方法是检查您的ExtendedAuthorize
属性,OnAuthorization
是否在希望用户重定向到的页面上运行。
我猜你ExtendedAuthorize
是类似以下内容:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class ExtendedAuthorizeAttribute : AuthorizeAttribute
{
private readonly string _redirectActionName;
private readonly string _redirectControllerName;
SimpleAuthorizeAttribute(string redirectActionName, string redirectControllerName)
{
_redirectActionName = redirectActionName;
_redirectControllerName = redirectControllerName;
}
public string RedirectActionName
{
get
{
return _redirectActionName;
}
}
public string RedirectControllerName
{
get
{
return _redirectControllerName;
}
}
}
在这种情况下,你只需要检查OnAuthorize是否是你想要的用户重定向到网页上运行:
public override void OnAuthorization(AuthorizationContext filterContext)
{
base.OnAuthorization(filterContext);
if(filterContext.ActionDescriptor.ActionName == RedirectActionName &&
filterContext.ActionDescriptor.ControllerDescriptor.ControllerName == RedirectControllerName)
{
return;
}
....
}
嗨。我测试过,'OnAuthorization'确实在重定向的页面上运行。我不知道如何做条件测试。干杯! – Celdor 2015-01-26 09:47:43
嗨,很高兴我可以帮助:) – 2015-01-26 18:25:39