开发者

response redirect with '+'

开发者 https://www.devze.com 2023-01-01 02:30 出处:网络
when I write Response.Redirect(\"Default2.as开发者_如何学Cpx?Name=\" + TextBox1.Text); then string input = Request.QueryString[\"Name\"];

when I write

Response.Redirect("Default2.as开发者_如何学Cpx?Name=" + TextBox1.Text);

then

string input = Request.QueryString["Name"];

if I write yahoo+music in textbox

the input will be yahoo music why ? and how can I keep the '+' ?


+ is the encoding for space in query strings. To encode + you need to use %2b.

Try UrlEncode which should handle this for you.


A plus in the URL means a space. You should URL encode the value that you put in the URL:

Response.Redirect("Default2.aspx?Name=" + Server.UrlEncode(TextBox1.Text));


I've another way - although a little bit 'tricky' - to reach your goal by passing '+'(or any other special character) in query string

when you pass the query string you write like this:

Response.Redirect("Default.aspx?Name="+TextBox1.Text.Replace("+","_"));

then it will pass Default.aspx?Name=Yahoo_Music

and to request it, just replace again

string input = Request.QueryString["Name"].Replace("_","+");

input will be: Yahoo+Music.

although this way a little bit tricky but sometimes this way very helpful to pass special character in query string.

Thanks

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号