views:

95

answers:

1

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

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

A: 

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

Aside: You might also want to start accepting answers to your questions. A 0% acceptance rate isn't going to go over well with some people, who might choose not to answer your questions.

tvanfosson
This is good solution but... I need to Rollback transaction because setting ExceptionHandled to true clears exception bubbling.PSI review my questions and answers. Unfortunately nobody give me answer which will be satisfactory. Probably yours will be first :)
dario-g