This code can help you.
protected void Application_Error(object sender, EventArgs e)
{
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
Server.ClearError();
}
However, instead of setting the status code in Global.asax, you should use authentication and authorization in web.config
source
share