首页 新闻 赞助 找找看

<a href ="文件路径"> 当文件路径中有%时就无法下载,提示bad request invalid url

0
悬赏园豆:5 [已解决问题] 解决于 2013-08-20 17:52

<a href ="文件路径"> 当文件路径中有%时就无法下载,提示bad request invalid url

c#
红尘中行的主页 红尘中行 | 初学一级 | 园豆:130
提问于:2013-08-20 11:43
< >
分享
最佳答案
0

输入:http://q.cnblogs.com/q/53747/%%%%%%%%%

提示:

Your browser sent a request that this server could not understand. Sorry for the inconvenience.
Please report this message and include the following information to us.
Thank you very much!

URL: http://
Server: lb-130114ay41d-4
Date: 2013/08/20 13:06:54

Powered by Tengine

 

所以,服务器不能理解这样的url,所以你从文件路劲中避免吧~

收获园豆:5
幻天芒 | 高人七级 |园豆:37175 | 2013-08-20 13:08

文件的确放在服务器上,是服务器的原因导致的吗?

是服务器太差了还是都是这样的?

非常感谢!

红尘中行 | 园豆:130 (初学一级) | 2013-08-20 14:07

@红尘中行: 是你的路劲里有%号,还是你的文件名有%号?应该是url编码造成的。

后台遇到%,会用url解码,然后解析不出来,所以就提示错误了(猜测待验证)

幻天芒 | 园豆:37175 (高人七级) | 2013-08-20 14:39

@幻天芒: 您的意思是url解析不出来。

文件名里有%号,因为要下载文件,所以说路径里也包含文件名。

在前台要下载除了<a href>之外还有其他方法吗?、

谢谢!

红尘中行 | 园豆:130 (初学一级) | 2013-08-20 15:06

@红尘中行: 

if (Request.Browser.Browser == "IE")
                name = Server.UrlEncode(name);
            Response.Clear();
            string filePath = Server.MapPath("~/Export/Excel/Expense/") + path + ".xlsx";
            //增加xls格式的文件下载
            if (System.IO.File.Exists(filePath))
            {
                Response.AddHeader("Content-Disposition", "attachment;fileName=" + name + ".xlsx");
            }
            else
            {
                filePath = filePath.Substring(0, filePath.Length - 1);
                Response.AddHeader("Content-Disposition", "attachment;fileName=" + name + ".xls");
            }
            Response.WriteFile(filePath);

类似的写法即可~这样路径就在后台被处理了,不经过url~
幻天芒 | 园豆:37175 (高人七级) | 2013-08-20 15:57

@幻天芒: 好的,谢谢!

红尘中行 | 园豆:130 (初学一级) | 2013-08-20 17:52
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册