4

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

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

dariol
  • 1,959
  • 17
  • 26

1 Answers1

2

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
  • 524,688
  • 99
  • 697
  • 795
  • This is good solution but... I need to Rollback transaction because setting ExceptionHandled to true clears exception bubbling. PS I review my questions and answers. Unfortunately nobody give me answer which will be satisfactory. Probably yours will be first :) – dariol Jan 18 '10 at 00:06