0

I have a web API method, that is defined like this:

[HttpPost]
[Route("{id:int}/whatever")]
[AuthorizeClass]
public async Task<IHttpActionResult> functionName(int id, [FromBody] JToken data)
{           
    //Do something....
    return Ok();
}

public class AuthorizeClass : AuthorizeAttribute
{
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            //Do something...
        }
}

In the OnAuthorization method I need to find the value of the id parameter, which seems to be held in the querystring.

I can find the whole string, but I want to specifically find it by its name, rather than deconstructing the query string - is this possible?

EDIT:

I have tried the answers in this question: Accessing QueryString in a custom AuthorizeAttribute

but they just return an empty array

Alex
  • 3,730
  • 9
  • 43
  • 94
  • My bad, I linked he wrong answer. Your `id` variable is in route data not the querystring. Look at this one: https://stackoverflow.com/a/16941399/16363 – Mark Oct 10 '18 at 12:04
  • @Mark that worked - if you mark that as the answer I will accept it.... – Alex Oct 10 '18 at 12:28

0 Answers0