Process Application_EndRequest in global.asax file. Part of the information from the article below (not my code):
protected void Application_EndRequest(Object sender, EventArgs e) { HttpContext context = HttpContext.Current; if (context.Response.Status.Substring(0,3).Equals("401")) { context.Response.ClearContent(); context.Response.Write("<script language="javascript">" + "self.location='../login.aspx';</script>"); } }
Take a look here for the full article.
source share