문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top