views:

52

answers:

1

Hi

I am trying to use the ActionFilterAttribute in asp.net mvc. What I want to do is check if the users subscription is expired if it is I want to redirect the user to a page if not then do nothing.

But the methods that you can override are all void. So how do I do this? Like I don't even know how to unit test it either since it is void.

public override void OnActionExecuting(ActionExecutingContext filterContext)
A: 

I think what you want is an Authorization Filter:

public override void OnAuthorization(AuthorizationContext filterContext)
{
    if (...subscriptionExpired...)
    {
        filterContext.Cancel = true;
        filterContext.Result = new RedirectResult("/user/login");
    }
}
dtb
Hmm I was hoping to break it up but I guess I can look into that. Why do you still have to set it to Cancel? can't you just redirect?
chobo2
I also dont' want to override the OnAuthorization
chobo2
@chobo2: why not?? That's the way to do it - why insist on **not** doing it that way? What's the motivation?
marc_s