How to prevent IIS7 for handling HTTP status code 401?

前端 未结 2 1390
夕颜
夕颜 2020-12-15 07:52

I\'m working my ASP.NET MVC 2 project. I create exception filter for catching unauthorized access exception that occur when user does not has permission to view some action.

2条回答
  •  北海茫月
    2020-12-15 08:23

    You can pass through IIS7 default error messages in two ways

    One is to set response.TrySkipIisCustomErrors to be true

    response.TrySkipIisCustomErrors = true;
    response.Status = response.Status;
    

    For some reason, TrySkipIisCustomErrors is not honoured if you don't set response.Status.

    The other is to set existingResponse to "PassThrough" in web.config

    
      
        
      
    
    

    But this will ignore all set IIS custom error pages.

提交回复
热议问题