Wednesday, 10 October 2012

Return content in ASP.NET with 503 Service Temporarily Unavailble

I tried to do this today on a nice looking holding page while we were doing some site maintenance:
Response.StatusCode = 503;
HttpContext.Current.Response.StatusDescription = "Service Temporarily Unavailable";
The problem was that my nice-looking content never got displayed. Instead, the user was presented with an ugly "The service is unavailable." page. To overcome this is a one-liner:
Response.TrySkipIisCustomErrors = true;