asp.net-mvcnhibernatestaleobjectstate

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?


Solution

  • 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;
        }
    }