现在的位置: 首页 > 综合 > 正文

.NET Tips: 正确获取当前URL

2013年10月12日 ⁄ 综合 ⁄ 共 334字 ⁄ 字号 评论关闭

获取当前URL我一直使用HttpContext.Current.Request.Url.ToString(),今天Tinyfool指出我的一个Bug,调试发现,ToString()函数并不可靠。

如果当前URL为
http://localhost/search.aspx?user=tinyfool&tag=%BC%BC%CA%F5
通过HttpContext.Current.Request.Url.ToString()获取到的却是
http://localhost/search.aspx?user=tinyfool&tag=¼¼Êõ
这显然不对,怎么办?用HttpContext.Current.Request.Url.PathAndQuery好了,这个得到的正确的。:)

抱歉!评论已关闭.