我试图从 ASP.NET 中的查询字符串中了解特殊字符。在其他所有浏览器中,这都能完美运行:mysite.com?s=smør
,但在 IE 中,它会将ø字母写成正方形。
我已经搜索了高低的解决方案并阅读了相关信息Server.UrlEncode()
,但Server.UrlEncode()
写道: sm%ef%bf%bdr 这对用户来说也不是很愉快;-)
在页面上的任何地方写 ÆØÅ 时,它都能完美运行,所以一定是因为它以某种方式来自查询字符串。
我的代码如下:
@* Check the searchterm querystring for null or empty value *@
if (HttpContext.Current.Request.QueryString["s"] != null && !string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["s"]))
{
string searchTerm = Server.UrlEncode(HttpContext.Current.Request.QueryString["s"]);
<span>@Server.UrlDecode(searchTerm)</span>
}
那么,有人知道如何解决这个问题吗?
提前致谢。
编辑
做了一个这样的快速修复/黑客攻击:
string rawUrl = Server.UrlDecode(HttpContext.Current.Request.RawUrl);
string searchTerm = rawUrl.Substring(rawUrl.IndexOf('=') + 1);
虽然它并不漂亮;-)