3

We have deployed an ASP.NET MVC applicaton to an Azure App Service.

If a request takes longer than 230 seconds Azure returns an error page "500 - The request timed out. The web server failed to respond within the specified time." - https://stackoverflow.com/a/38676086

We are making changes to ensure less processing is done on the Web request, however there may still be a chance that these limits are hit. Does anyone know if there is a way to configure a custom error page to be shown instead of the generic error page shown below?

Azure 500 - The request timed out page

jdtaylor
  • 334
  • 2
  • 5
  • 20
  • If there is a chance that you can reach 230 seconds limit I can assume that there is definitely something wrong with your app... – Roman Borovets Dec 20 '17 at 14:16
  • We currently have a long running database query that is being performed on a web request, we are in the process of moving it but until then we would like to show a custom error page. – jdtaylor Dec 20 '17 at 15:12

2 Answers2

0

This article should help you, remember that a custom error only works if the request reach the website. http://benfoster.io/blog/aspnet-mvc-custom-error-pages

Jarnstrom
  • 467
  • 2
  • 6
  • Thanks for the response, the error page is being served by Azure and not by our application so this approach won't work. We already have customErrors configured for the application. – jdtaylor Dec 20 '17 at 13:34
0

We are making changes to ensure less processing is done on the Web request, however there may still be a chance that these limits are hit. Does anyone know if there is a way to configure a custom error page to be shown instead of the generic error page shown below?

Since you could not overcome the limitation about request timeout (230 second) in Azure App Service, you need to either optimize your server-side processing or you need to catch the exception and customize the response. I tried to capture the exception by using Application_Error event and custom HTTP Modules, but failed in the end.

For a workaround, you could specify the timeout for your action and capture the exception in your application before the timeout exception thrown by Azure App Service, then you could add your custom error page. You could leverage AsyncTimeoutAttribute and define your action as follows:

[AsyncTimeout(duration:10000)] //The timeout value in milliseconds.
[HandleError(ExceptionType = typeof(TimeoutException),
                            View = "TimeoutError")]
public async Task<ActionResult> LongTask(CancellationToken cancellationToken)
{
    await Task.Delay(TimeSpan.FromSeconds(20), cancellationToken);
    return Content("Done");
}

Note: HandleErrorAttribute requires customErrors to be enabled in your Web.Config. If the TimeoutException happens, then you would be redirected to the particular MVC view you defined.

Bruce Chen
  • 18,207
  • 2
  • 21
  • 35
  • Thanks, your solution looks good but would involve a number of changes to our application, we ideally would just like to configure Azure to display a static html page or redirect to a custom error page when it's 230 second timeout is hit, do you know if there's anyway to configure this within Azure? – jdtaylor Dec 21 '17 at 09:13
  • Moreover, if you are using Azure VM or Cloud Service, the idle timeout for Azure Load Balancer is configurable, details you could follow [here](https://azure.microsoft.com/en-us/blog/new-configurable-idle-timeout-for-azure-load-balancer/). For Azure Web Apps, you need to optimize your server-side processing. – Bruce Chen Dec 22 '17 at 02:15