2

I've noticed that whatever method I use for obtaining the current requests URL, the query string ampersands are always encoded.

Request.RawUrl
Request.Url
HttpContext.Current.Request.Url.AbsoluteUri

Will always produce encoded results (notice the &):

/Controller/View?arg1=weffe&arg2=wefwe&arg3=wefewge
http://domain/Controller/View?arg1=weffe&arg2=wefwe&arg3=wefewge
http://domain/Controller/View?arg1=weffe&arg2=wefwe&arg3=wefewge

How do I ensure the returned URL is not encoded in this fashion, and appears as such:

/Controller/View?arg1=weffe&arg2=wefwe&arg3=wefewge
http://domain/Controller/View?arg1=weffe&arg2=wefwe&arg3=wefewge

Any help much appreciated - I'm sure I've missed something obvious here!

4
  • Are you using the url in the view? or in the controller? Commented Feb 8, 2012 at 19:48
  • Are you sure that your incoming Url is actually arg1=www&arg2=eee? Check out what browser actually navigates/requests. Commented Feb 8, 2012 at 19:55
  • @ChadRuppert - I am using the Url in the View. Commented Feb 8, 2012 at 22:36
  • @AlexeiLevenkov - Yes, the incoming url is definitely as written. Commented Feb 8, 2012 at 22:37

2 Answers 2

4

Is the URL actually encoded, or are you outputting it to the browser, and the output in the browser is encoded? If this is the case you can fix by using @Html.Raw(url) to bypass MVC's auto HTML encoding.

Sign up to request clarification or add additional context in comments.

2 Comments

This is why i asked my question. Good call.
Thanks, I knew it would be something simple, but for some reason I couldn't find out what was needed! SO Saves the day again...!
2

Print your url without encoding it with:

@Html.Raw(Request.Url)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.