Run both Authorize Filter and Action Filter on unauthenticated ASP.NET MVC request

Posted by Bryan Migliorisi on Stack Overflow See other posts from Stack Overflow or by Bryan Migliorisi
Published on 2010-03-17T03:28:29Z Indexed on 2010/03/17 3:31 UTC
Read the original article Hit count: 634

I have decorated my base controller with a couple of action filters. They work fine.

One of those filters sets up the request - does things like set the culture based on the domain, etc.

I also have a handful of actions that require authorization using the Authorize attribute.

My problem is that when an user attempts to request a page they are not authorized to access, the authorization filter kicks in and redirects them to a page telling them that they cannot vie the page.

The issue is that the action filters never run so the culture and other request data is never set. This effectively causes language to be wrong in the view and other data to be missing.

I know that authorization filters run first but my question is this: How can I design this such that I can ensure that certain methods are always run before the view is returned, regardless of the authorization.

Hope that makes sense.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about c#