WebAPI- Query String Value from HttpRequest Url
In Web Api, always need to get query string value with the specified query string name from httprequest.

namespace QueryStringExtension
{
public static class StringExtension
{
public static string GetSQueryString(this HttpRequestMessage request, string key)
{
var queryStrings = request.GetQueryNameValuePairs();
if (queryStrings == null)
return null;
var match = queryStrings.FirstOrDefault(kv => string.Compare(kv.Key, key, true) == 0);
if (string.IsNullOrEmpty(match.Value))
return null;
return match.Value;
}
}
}


Comments
Post a Comment