尝试在登录对话框显示下方执行代码时,如果我取消登录错误,则会由于凭据无效而拒绝未经授权的访问。
protected void Application_EndRequest(object sender, EventArgs e)
{
//verify that resquest is for api
if (Request.Path.ToLower().StartsWith("/api/v1"))
{
if (Response.StatusCode == 302)
{
Response.StatusCode = 401;
Response.ContentType = "application/json";
Response.ClearContent();
Response.Write("\"fail\"");
}
else if (Response.StatusCode == 500)
{
Response.StatusCode = 500;
Response.ContentType = "application/json";
Response.ClearContent();
Response.Write("\"server error\"");
}
}
}