How can I read the post form parameter values using the Request in web api? I have a controller
[Route("")]
[HttpPost]
[AuthenticationAttribute]
public void PostQuery()
{
//some code
}
I have defined AuthenticationAttribute class seperately
public class AuthenticationAttribute : Attribute, IAuthenticationFilter
{
public Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken)
{
// I want to read the post paramter values over here
}
public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
{
return Task.Run(
() =>
{
});
}
public AuthenticationAttribute()
{
}
}
I want to check the post parameter in the AuthenticateAsync function.
I tried doing
context.Request.Content.ReadAsStringAsync().Result;
but this string is empty. I am able to read the query parameters using
context.Request.GetQueryNameValuePairs();
But could not find a way to get the post form parameters. Any help is appreciated.
var reader = new StreamReader(HttpContext.Current.Request.InputStream);
var content = reader.ReadToEnd();
var jObj = (JObject)JsonConvert.DeserializeObject(content);
foreach (JToken token in jObj.Children())
{
if (token is JProperty)
{
var prop = token as JProperty;
if (prop.Name.Equals("skipExternal") && prop.Value.ToString().Equals("True"))
{
// Logic...
}
}
}
This is the code I used. I wanted to check weather the parameter skipExternal
was sent as True
in post parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With