IActionFilter Redirect in MVC3
I am implementing an IActionFilter to authenticate the request in MVC3, if my authentication returns false I want to redirect the request to a different controller from within the IActionFilter.
I would like to be able to kill the processing of the current request and totally redirect the request to a different c开发者_开发技巧ontroller action.
I am also willing to use the IAuthorizationFilter but this appears for the most part the same as the IActionFilter.
Thanks for the help.
There are several ways to accomplish this - some good ways provided here: Redirecting to specified controller and action in asp.net mvc action filter
In a nutshell you can either ctx.Response.Redirect() or create a new route as the result of your filter context.
Ensure wherever you redirect to won't fail authentication though or you can get stuck in a loop unless you code in your specific url which is somewhat hacky.
If you have a problem with this, post back we'll help you out, but that should work just fine.
精彩评论