Profile picture Schedule a Meeting
c a n d l a n d . n e t

Monorail: Exception Handlers: Flash and Redirect

Dusty Candland | |

e setting up exception chaining on monorail, I wanted to use the Flash properties to store the LastException for next request, an error page. This by default doesn't work if the exception happens outside of the Castle.MonoRail.Framework.MonoRailHttpHandler.Process method. This is because the Flash variables don't get saved until after this method. One note here, the Process method is wrapped in a try, finally block and the Flash properties will be saved in the case of an exception on the Process method, some additional checking in the exception handler may be needed to catch this. Anyway, I added the following line to my last handler and the Flash properties are working great.

context.Session[Flash.FlashKey] = context.Flash;

Secondly, I wanted to redirect to different views based on the exception, which I wasn't able to do. The reason was that the asp.net framework noticed the exception an handled according, not what I wanted. The way around this is to clear the error using the Server.ClearError() method before redirecting.

context.UnderlyingContext.Server.ClearError();

Webmentions

These are webmentions via the IndieWeb and webmention.io. Mention this post from your site: