Accessing post or get parameters in custom authorization MVC4 Web Api

后端 未结 5 1033
轮回少年
轮回少年 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:13

    I accessed the context route data to get the parameters from within a custom AuthorizeAttribute when calling something like /api/client/123/users:

    public class CustomAuthorizeAttribute : AuthorizeAttribute
      {
         protected override bool IsAuthorized(System.Web.Http.Controllers.HttpActionContext actionContext)
         {
            var clientId = Convert.ToInt32(actionContext.ControllerContext.RouteData.Values["clientid"]);
    
            // Check if user can access the client account.
    
         }
      }
    

提交回复
热议问题