Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have also encountered this problem.</p> <p>To work around it I wrote the following method which I call from within the OnAuthorization method:</p> <pre><code>private static object GetValueFromActionContext(HttpActionContext actionContext, string key) { var queryNameValuePairs = actionContext.Request.GetQueryNameValuePairs(); var value = queryNameValuePairs .Where(pair =&gt; pair.Key.Equals(key, StringComparison.OrdinalIgnoreCase)) .Select(pair =&gt; pair.Value) .FirstOrDefault(); var methodInfo = ((ReflectedHttpActionDescriptor) (actionContext.ActionDescriptor)).MethodInfo; var parameters = methodInfo.GetParameters(); var parameterType = parameters.Single(p =&gt; p.Name.Equals(key, StringComparison.OrdinalIgnoreCase)).ParameterType; var converter = TypeDescriptor.GetConverter(parameterType); return converter.ConvertFromString(value); } </code></pre> <p>This code makes the following assumptions:</p> <ul> <li><p>The key you are extracting matches an argument name on the action method.</p></li> <li><p>The parameter type you are obtaining will have a converter valid for the type.</p></li> <li><p>You are not using any custom binding or formatting on the parameter.</p></li> </ul> <p>In the scenario that I am using the code I am only expecting simple types such as Guid, Boolean, String etc and could be customised as per your requirements.</p> <p>The extension method GetQueryNameValuePairs is part of the System.Net.Http.HttpRequestMessageExtensions class and will read querystring / form data.</p> <p>Example use:</p> <pre><code>object folderId = GetValueFromActionContext(actionContext, "folderId"); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload