MVC中施用AuthorizeAttribute做身份验证操作怎么解决

如题所述

代码顺序为:OnAuthorization-->AuthorizeCore-->HandleUnauthorizedRequest

如果AuthorizeCore返回false时,才会走HandleUnauthorizedRequest 方法,并且Request.StausCode会返回401,401错误又对应了Web.config中

<authentication mode="Forms">
<forms loginUrl="~/" timeout="2880" />
</authentication>
所有,AuthorizeCore==false 时,会跳转到 web.config 中定义的 loginUrl="~/"
温馨提示:答案为网友推荐,仅供参考
相似回答