IIS7 Overrides customErrors when setting Response.StatusCode?
        Posted  
        
            by Nicholas H
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Nicholas H
        
        
        
        Published on 2009-01-12T02:37:56Z
        Indexed on 
            2010/04/28
            14:03 UTC
        
        
        Read the original article
        Hit count: 325
        
Having a weird problem here. Everybody knows that if you use web.config's customErrors section to make a custom error page, that you should set your Response.StatusCode to whatever is appropriate. For example, if I make a custom 404 page and name it 404.aspx, I could put <% Response.StatusCode = 404 %> in the contents in order to make it have a true 404 status header.
Follow me so far? Good. Now try to do this on IIS7. I cannot get it to work, period. If Response.StatusCode is set in the custom error page, IIS7 seems to override the custom error page completely, and shows it's own status page (if you have one configured.)
Has anyone else seen this behavior and also maybe know how to work around it? It was working under IIS6, so I don't know why things changed.
Update: This is not the same as the issue in http://stackoverflow.com/questions/347281/asp-net-custom-404-returning-200-ok-instead-of-404-not-found
© Stack Overflow or respective owner