如何使 Forms 驗證遇到401不轉自動轉向到登錄頁面?而是直接返回StatusCode 返回給客戶端?
2 回答

蠱毒傳說
TA貢獻1895條經驗 獲得超3個贊
<customErrors defaultRedirect="errorStatus.htm" mode="On">
</customErrors>
filenotfound.htm這個頁面再寫上401問題的一些原因。
第二種方法:
protected void Application_EndRequest(object sender,EventArgs e) { HttpContext context =HttpContext.Current; if(Response.StatusCode==401) { Response.ClearContent(); json =JsonConvert.ExportToString("Invalid API key or no API key was provided."); context.Response.Write(json); } }
- 2 回答
- 0 關注
- 656 瀏覽
添加回答
舉報
0/150
提交
取消