Gérard Lambert
Gérard Lambert

Reputation: 43

ASP.NET MVC / Get raw value from query string

How can I get the raw value corresponding to a parameter from a query string in ASP.NET MVC (5.2.7) ?

Currently, I am only able to get the decoded value. For example, with the query string p=lol%20cat, the code below returns "lol cat" :

string decoded = Request.QueryString["p"]; // "lol cat"

When my query string is p=lol%20cat, I want to get "lol%20cat".
Also, if it is p=lol+cat, I want to get "lol+cat".

I could build something myself using System.Web.HttpRequestBase or System.Uri but I would prefer to use something reliable, built-in the .NET Framework.

Upvotes: 2

Views: 836

Answers (1)

AzureDevForSF
AzureDevForSF

Reputation: 49

Try using

Request.Url.Query 

This returns the raw querystring as a string.

Upvotes: 1

Related Questions