HyperLink控件NavigateUrl属性包含中文文件名时被截断问题

magicbacon 2008-10-30 11:10:17
各位好:我的HyperLink包含在DataGrid控件中,它的NavigateUrl属性用了Server.UrlEncode()加入了中文文件名,但是由于太长会被截断(长度应该没有超过255),请问有什么解决办法吗?

我在这个帖子里看到相似的问题,但是好像也没有好的解决办法:http://topic.csdn.net/u/20080825/11/5f83bbca-18d3-47e1-af37-f1cc7833ff76.html

有个仁兄说转成utf-8编码,请问怎样转呢?
...全文
182 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
mengxj85 2008-10-30
  • 打赏
  • 举报
回复
学习,没遇见过
takeshe 2008-10-30
  • 打赏
  • 举报
回复
学习~
magicbacon 2008-10-30
  • 打赏
  • 举报
回复
嗯,我也觉得问题是出现在程序上,各位有什么好的办法吗?
wfyfngu 2008-10-30
  • 打赏
  • 举报
回复
wfyfngu 2008-10-30
  • 打赏
  • 举报
回复
找到了,楼主看看
问题出在程序上,而不是浏览器上

Maximum URL length is 2,083 characters in Internet Explorer
View products that this article applies to.
Article ID : 208427
Last Review : October 27, 2007
Revision : 3.5
This article was previously published under Q208427
SUMMARY
Microsoft Internet Explorer has a maximum uniform resource locator (URL) length of 2,083 characters. Internet Explorer also has a maximum path length of 2,048 characters. This limit applies to both POST request and GET request URLs.

If you are using the GET method, you are limited to a maximum of 2,048 characters, minus the number of characters in the actual path.

However, the POST method is not limited by the size of the URL for submitting name/value pairs. These pairs are transferred in the header and not in the URL.

RFC 2616, "Hypertext Transfer Protocol -- HTTP/1.1," does not specify any requirement for URL length.
REFERENCES
For a further breakdown of the components, see the Wininet header file.

For more information, see "General Syntax," section 3.2.1 of RFC 2616, "Hypertext Transfer Protocol -- HTTP/1.1," at the following Internet Society Web site:
ftp://ftp.isi.edu/in-notes/rfc2616.txt
magicbacon 2008-10-30
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wf5360308 的回复:]
没遇过UrlEncode后 被截取的情况,试试:
System.Web.HttpUtility.UrlEncode("xx", System.Text.Encoding.UTF8);
[/Quote]

这样还是一样哦~

各位有什么好的替代办法吗?
magicbacon 2008-10-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wfyfngu 的回复:]
IE支持的URL长度应该远远不止255个(这个回头我去查相关文档)

就算是255个,
一个汉字通常被编码成3个字符
那么 255/3 = 85
85个汉字的文件名还是比较少见
而DOS下,也根本不受支持
[/Quote]

是这样的,从状态栏里看到的,实际不是很长哦~
jimu8130 2008-10-30
  • 打赏
  • 举报
回复
如果有个文件名(包含路径)与一个特定id的映射表就好了
冷月孤峰 2008-10-30
  • 打赏
  • 举报
回复
没遇过UrlEncode后 被截取的情况,试试:
System.Web.HttpUtility.UrlEncode("xx", System.Text.Encoding.UTF8);
wfyfngu 2008-10-30
  • 打赏
  • 举报
回复
IE支持的URL长度应该远远不止255个(这个回头我去查相关文档)

就算是255个,
一个汉字通常被编码成3个字符
那么 255/3 = 85
85个汉字的文件名还是比较少见
而DOS下,也根本不受支持
gongsun 2008-10-30
  • 打赏
  • 举报
回复
up
周公 2008-10-30
  • 打赏
  • 举报
回复
Server.UrlEncode()后有可能会超过255的,截断是Server.UrlEncode()之后的数据的。
Nobel0429 2008-10-30
  • 打赏
  • 举报
回复
保存的时候点 高级保存 然后用utf-8保存一下看看
sunxw18 2008-10-30
  • 打赏
  • 举报
回复
不是被截断了吧,截断了 “班”变不成“口”
口的编码为:%e5%8f%a3
班的编码为:%e7%8f%ad

两个的长度都是一样的,不是截取的问题吧!
wfyfngu 2008-10-30
  • 打赏
  • 举报
回复
把你要传的字符串和被截断后的字符串贴出来看看
单独测试
Server.URLEndcode("超长的中文字符")
javascript:escape("超长的中文字符")
对比一下输出结果

另外,如果条件允许,用下面的方法试一下看能不能解决问题(需要引用 Microsoft.JScript.dll )
Microsoft.JScript.GlobalObject.escape()

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧