There are a couple big pieces to the ActionFilter Scenario, let’s break them down

  • The ActionFilter to catch the exception
  • Setting the filterContext.Result which is of type ActionResult
  • Configuring your DnnController to have a method and/or Action available to handle the error redirect

Your ActionFilter code should be almost identical to how you would solve this same problem in an ASP.NET MVC website. The trick is having your HomeController in our example configured to return an ActionResult that can be processed.

Note that the HomeController now has 2 Actions

  • Error
  • RedirectToError

The ActionResult that is generated from these methods is piped into the filterContext and when the ActionFilter finishes processing the page will be updated.

My personal preference is setting up these 2 Actions. This allows us to specify a Redirect which will update the url in the browser and completely move the user off the page that errored out. You technically don’t have to use the 2 actions but I consider it a best practice for handling the routes.


Originally posted at read the original here