dariol
dariol

Reputation: 1979

Where to handle StaleObjectStateException in asp.net mvc application?

I'm using Session per Request pattern. Transactions are managed automatically.

How can I easily handle StaleObjectStateException and show some specific view?

Upvotes: 3

Views: 510

Answers (1)

tvanfosson
tvanfosson

Reputation: 532435

You might want to override OnException in your controller and if a StateObjectStateException occurs, you could set the Result on the ExceptionContext to your error view result.

public override void OnException( ExceptionContext context )
{
    if (context.Exception is StateObjectStateException)
    {
        context.Result = View("error");
        context.ExceptionHandled = true;
    }
}

Upvotes: 2

Related Questions