Accessing post or get parameters in custom authorization MVC4 Web Api

后端 未结 5 1016
轮回少年
轮回少年 2020-11-29 02:38

Is it possible to access post or get parameters via the HttpActionContext object?

I have a set of sensors that loggs data to a web server that provides a REST api.

5条回答
  •  温柔的废话
    2020-11-29 03:23

    You can access query string values from your custom authorize attribute by using the following code:

    public class ApiAuthorizationFilter : AuthorizeAttribute
    {
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            var querystring = filterContext.RequestContext.HttpContext.Request.QueryString;
            // Do what you need
        }
    }
    

提交回复
热议问题