鍍金池/ 問答/C#/ asp.net mvc 默認(rèn)身份認(rèn)證失效事件

asp.net mvc 默認(rèn)身份認(rèn)證失效事件

ASP.NET 4.0中,使用默認(rèn)的身份認(rèn)證,在web.config中配置如下:

<authentication mode="Forms">
  <forms defaultUrl="~/" loginUrl="~/Account/Login" name=".ticket" timeout="30" slidingExpiration="true" />
</authentication>
<authorization>
  <deny users="?" />
</authorization>

默認(rèn)情況下,身份失效時瀏覽器會跳轉(zhuǎn)到登錄頁,并在后面帶returnUrl參數(shù),參數(shù)值為跳轉(zhuǎn)前的url,現(xiàn)在想重寫這個跳轉(zhuǎn)事件,自定義跳轉(zhuǎn)的url以及參數(shù),怎么辦?

回答
編輯回答
葬憶

1.可以自定義 AuthorizeAttribute ,重寫其中的 OnAuthorization 或 HandleUnauthorizedRequest 方法。
2.如果使用了自定義的 BaseController ,也可在 BaseController 中進(jìn)行處理。

2017年10月27日 04:04