新问题是HttpUtilities.UrlEncode()方法将空格()转换为plusses()而不是像浏览器想要的那样.因此,文件图像name.jpg被正确找到时,文件图像name.jpg将返回not-found.
值得庆幸的是,一位同事向我指出了HttpUtilities.UrlPathEncode(),它用于代替空格.
为什么有两种处理Url编码的方法?为什么有两个命令行为如此不同?
解决方法
UrlPathEncode只是替换了URL中无法使用的所有字符,例如<,>和.
两条MSDN链接都包含此引用:
You can encode a URL using with the UrlEncode method or the UrlPathEncode method. However,the methods return different results. The UrlEncode method converts each space character to a plus character (+). The UrlPathEncode method converts each space character into the string “%20”,which represents a space in hexadecimal notation. Use the UrlPathEncode method when you encode the path portion of a URL in order to guarantee a consistent decoded URL,regardless of which platform or browser performs the decoding.
原文地址:https://www.jb51.cc/aspnet/251309.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。