Question

Hi,

I am about to validate some data before letting the user in to the action and if the data do not validate, then I need to redirect to another action.

The question is how I get the post data that is sent to the action from within the AuthorizeAttribute?

Was it helpful?

Solution

I'm not sure if this is what you are asking for, but this will give you access to the request data from within your MyAuthorizeAttribute.

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class MyAuthorizeAttribute : FilterAttribute, IAuthorizationFilter
{
    public void OnAuthorization(AuthorizationContext filterContext)
    {
        var httpContext = filterContext.RequestContext.HttpContext;
        var request = httpContext.Request;
        // do stuff with request
    }
}

You can then get any data that was sent in the request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top