简体   繁体   中英

Obtaining current URL - when the URL includes a query string with multiple values

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!

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.

打印您的网址,而不用以下方式对其进行编码:

@Html.Raw(Request.Url)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM