customerrors for 401.2 in ASP.NET

后端 未结 4 849
梦谈多话
梦谈多话 2020-12-19 03:57

I successfully implemented role based authorization in ASP.NET. When a person does not have the needed role he gets to see an error page for 401.2 not authorized.

W

4条回答
  •  没有蜡笔的小新
    2020-12-19 04:13

    Here's what worked well for me.

    Global.asax -

        protected void Application_EndRequest(object sender, EventArgs e)
        {
            if (Response.StatusCode == 401 && Request.IsAuthenticated)
            {
                Response.StatusCode = 303;
                Response.Clear();
                Response.Redirect("~/AccessDenied.html");
                Response.End();
            }
        }
    

    Web.config -

      
        
          
        
        
      
      
        
          
            
          
        
      
      
        
          
            
            
          
        
      
    

    This takes care of the double 401 before a 200 issue as well. Also circumvents the pesky firefox authentication popup.

提交回复
热议问题