Is it possible to use custom error pages with MVC site but not Web API?

前端 未结 3 1289
旧时难觅i
旧时难觅i 2020-12-08 02:29

I have an MVC project with a /api folder which contains my Web API controllers. I want the following things:

  • My MVC site to serve a custom error page when an e
3条回答
  •  离开以前
    2020-12-08 03:04

    Well, after a nearly a year of letting this question marinade, I gave it another shot. Here's the web.config magic that got me what I wanted:

    
    
        
          
          
            
          
        
    
    
    
    
          
          
          
          
          
          
          
          
        
    

    The crux of what's going on here is that the node allows you to override settings made at a less specific path. So while we have errorMode="Custom" for path=".", we override that for the our Web API's path with the node, and the httpErrors configuration within it.

    I had seen nodes before, but it didn't dawn on me that this was their purpose until now. This article goes into more detail on the configuration inheritance model of IIS/.NET, which I found very informative: http://weblogs.asp.net/jongalloway/10-things-asp-net-developers-should-know-about-web-config-inheritance-and-overrides

提交回复
热议问题