C#的Web MVC +角如何防止URL编码传递参数时,方法在MVC控制器
我有我的网页上的链接如下:
<a ng-show="channel.ArtistImagepath != null" ng-href="/channel/DownloadImageFile/?filepath={{channel.ArtistImagepath}}" target="_blank"><i class="fa fa-download" style="color: green"></i> Artist Image</a><br/>
当我复制链接我浏览器是:
//mysite/channel/DownloadImageFile/?filepath=ChannelUploads/b51535d5-4ea3-45ae-bda4-332a0ce19ee8Artist+Gomez.jpg
当我点击的文件路径发送到我的控制器的链接是: ChannelUploads/b51535d5-4ea3-45ae-bda4-332a0ce19ee8ArtistDina Gomez.jpg
正如您所看到的,由于URL已被编码,所以+号被替换为文件名中的空格。这将导致错误未找到现有的我的服务器上message..the实际文件名的文件是:b51535d5-4ea3-45ae-bda4-332a0ce19ee8Artist + Gomez.jpg
public ActionResult DownloadImageFile(string filepath)
{
filepath = "https://marvment.com/" + filepath;
var type = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
var path = Path.GetFileName(filepath);
path = HttpUtility.UrlEncode(path);
//path = ToUrlFriendlyString(path);
using (var client = new WebClient())
{
var buffer = client.DownloadData(filepath);
return File(buffer, type.ToString(), path);
}
}
如何防止文件名从beign网址编码之前发送到我的控制器? 我想在文件名中保留+号,并在我的MVC控制器中处理编码。
我试过了,不断收到错误:https://docs.angularjs.org/error/$injector/unpr?p0 = escapeFilterProvider%20%3C-%20escapeFilter – user1526912 2015-03-08 23:02:43