查询字符串包含特殊字符 [英] Query strings with special characters
本文介绍了查询字符串包含特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何传递一个查询字符串包含特殊字符?
例如我需要通过与&
:我的查询字符串如下内 ../ solrresults.asp模式=搜索和;数据= M&安培;小号
解决方案
使用 HttpServerUtility .UrlEn code :
URL编码可确保所有浏览器将正确的URL字符串中的传输文本。字符如问号,连字符(安培)(?),斜杠(/)和空格可能会被某些浏览器被截断或损坏
块引用>MSDN:
字符串MyURL;
MyURL =http://www.contoso.com/articles.aspx?title=+ Server.UrlEn code(ASP.NET示例);回复于(&下; A HREF =+ MyURL +> ASP.NET实施例< / A>中);在传统的ASP使用 Server.URLEn code 是这样的:
< A HREF =page2.asp名=<%= Server.URLEn code(SNAME)%>>此处< / A>
How I can pass a query string with special characters?
For example I need to pass "&" inside my query string as below:
../solrresults.asp?mode=search&data=M & S
解决方案Use HttpServerUtility.UrlEncode:
URL encoding ensures that all browsers will correctly transmit text in URL strings. Characters such as a question mark (?), ampersand (&), slash mark (/), and spaces might be truncated or corrupted by some browsers.
MSDN:
String MyURL; MyURL = "http://www.contoso.com/articles.aspx?title=" + Server.UrlEncode("ASP.NET Examples"); Response.Write("<a href=" + MyURL + "> ASP.NET Examples </a>");
In classic ASP use Server.URLEncode this way:
<a href="page2.asp?name=<%= Server.URLEncode(sName) %>">here</a>
这篇关于查询字符串包含特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文