handling Execution Timeout Expired errors

M J 661 Reputation points
2024-03-05T17:44:32.5933333+00:00

I have an ASP.Net MVC application that has some reports that can throw Execution Timeout Expired errors.

I have already set a longer execution timeout in my controller and have also doubled the standard execution timeout in my connection string.

There are still instances where a few people are trying to search all records with limited input using a wild card. For these few instances I want to handle this in my catch block and display a custom message instead of having them see my generic error message that is displayed.

My question is this: Is there a way to do something like this?

catch (Exception ex)
{
    if (ex == System.TimeoutException)
    {
        Errors.ErrorOccured(ex);
        return RedirectToAction("TimeoutError", "Error");
    }
    Errors.ErrorOccured(ex);
}
return RedirectToAction("InternalServerError", "Error");
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,264 questions
{count} votes

Accepted answer
  1. Michael Taylor 48,486 Reputation points
    2024-03-05T19:06:04.3066667+00:00

    Assuming the exception being thrown is a timeout exception then yes you can do it.

    try
    {
       //Lengthy work here
    } catch (TimeoutException ex)
    {
        Errors.ErrorOccured(ex);
        return RedirectToAction("TimeoutError", "Error");
    } catch (Exception ex)
    {    
        Errors.ErrorOccured(ex);
        return RedirectToAction("InternalServerError", "Error");
    };
    
    //Everything succeeded so keep going...
    
    0 comments No comments

0 additional answers

Sort by: Most helpful