asp.net – 为什么HttpUtility.UrlEncode(HttpUtility.UrlDecode(“”))返回而不是?

我有一个文件下载的问题,下载正在用下划线替换所有的空格.

基本上我在这里遇到一个问题:

response.addheader("Content-disposition","attachment; filename=" + someFileName);

问题是如果someFileName中有一个空格,例如“check this out.txt”,那么用户会被提示下载“check_this_out.txt”.

我认为最好的选择是UrlEncode文件名,所以我试过

HttpUtility.UrlEncode(someFileName);

但它正在用加号替代空格,这使我失望了.所以我刚才试过

HttpUtility.UrlEncode(HttpUtility.UrlDecode("%20"))

并且解码工作正常并给我一个空间,但是编码占用空间,然后再次给我加号.

在这里缺少什么,这是正确的吗?如果是这样,我应该如何正确地将空格编码成’s’,这就是我所需要的.

解决方法

报价从 this link

I’ve come across this myself. If you
are able to change the spaces to %20s
then IE7 will convert them correctly.
Firefox though will take them
literally ( at least when using the
Content-disposition header) so you
will need to do this for requests from
IE7 only.

We did the following in our app. ( a
tomcat based document repository)

06000

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....