0

What is the best way to control user access to a controller. I have local User object with a property(boolean - "IsSubscribed"). Users can only access the controller if the value is true.

Notes:

I use forms authentication, but NO .net membership/profile etc.

mvc version 2

1 Answer 1

2

You could write a custom Authroize attribute:

public class CustomAuthorizeAttribute : AuthorizeAttribute
{
    protected override bool AuthorizeCore(HttpContextBase httpContext)
    {
        var isAuthorized = base.AuthorizeCore(httpContext);
        if (isAuthorized)
        {
            // Perform your custom authorization and return true/false
        }
        return isAuthorized;
    }
}

and then decorate your controller/actions with this attribute.

Sign up to request clarification or add additional context in comments.

2 Comments

1.So do we go like [Authorize(...)] public ActionResult myAction() (or) [CustomAuthorize(...)] public ActionResult myAction()
@maxxxee, [CustomAuthorize] public ActionResult MyAction() { ... }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.