Stop Response.Redirect from encoding

The URL string created after this response.redirect causes us a headache. It replaces characters with URL characters and the addition of additional file directories.

Response.Redirect("TestingReport.aspx?id=" + Request.QueryString("id") + "&Test_Type_ID=" + Request.QueryString("Test_Type_ID") + "&TType=" + Request.QueryString("TType")) 

https://subdomain.domain.com/User%20Portal/Testing/%2fUser%2520Portal%2fTesting%2fTestingReport.aspx%3fid%3d8444%26Test_Type_ID%3d2%26TType%3dCore%20Mandatory20

Why is this changing? and = percentage codes? I do not understand why it adds User Portal / Testing twice.

thanks

+6
source share
5 answers

It is called URLEncoding . Checkout this online utility to decode the string you have. In .NET, you can use System.Web.HttpUtility for encoding / decoding.

+2
source

Make sure your URL is empty.

0
source

The whole url gets the url, which is probably due to the fact that you are not encoding the urls of the values ​​you insert into the string. The URL will encode the values ​​correctly and it should work:

 Response.Redirect( "TestingReport.aspx?id=" + Server.UrlEncode(Request.QueryString("id")) + "&Test_Type_ID=" + Server.UrlEncode(Request.QueryString("Test_Type_ID")) + "&TType=" + Server.UrlEncode(Request.QueryString("TType")) ) 
0
source

Perhaps you want to build your query string separately from the line of the redirect method, the URL will encode these values, and then HTML will encode the URL passed to Response.Redirect

An example shown on the MSDN website. I suspect that your concatenation operations somehow force the URL structure to encode the whole thing, not just the values.

 <% 

dim qs

 qs = Server.URLEncode(Request.Querystring) Response.Redirect "newpage.asp?" + Server.HTMLEncode(qs) %> 

http://msdn.microsoft.com/en-us/library/ms524309.aspx

0
source

Mark this post . Basically .Net is trying to sanitize the url for you and mess it up. The solution is to manually encode it.

0
source

Source: https://habr.com/ru/post/891582/


All Articles