Tag: content disposition

Content-Disposition文件名无法在IE上运行

我正在开发一个asp.net/c# web应用程序,允许用户查看和下载PDF文件。 当我点击一个文件时,我会在浏览器中可用的PDF阅读器中查看,当我保存它时,该文件应该保存为我通过标题传递的名称。 但这不是IE7和IE8中的行为 FileInfo f = new FileInfo(FileName); Response.ContentType = “application/pdf”; Response.AddHeader(“Content-Disposition”, “inline; filename=” + f.Name) 当我单击以保存文件时,我发送的文件名不用于保存文件,但正在使用URL中的aspx页面的文件名。 这是IE中的一个错误。 当我在Google Chrome上试用它时,一切正常。

获取没有Content-Disposition的文件名

我正在寻找这个问题的解决方案好几天,我找不到任何。 我想从带有webclient的web服务器下载文件。 下载工作正常,但我无法获得真正的文件名,这对我来说非常重要。 我在许多主页上看过,文件名应该保存在Content-Disposition-Header中。 不幸的是,这个网站的标题是空的。 我试着用它: string header_contentDisposition =””; using (WebClient client = new WebClient()) { client.OpenRead(link); header_contentDisposition = client.ResponseHeaders[“Content-Disposition”]; MessageBox.Show(header_contentDisposition); } 此标题中没有保存信息。 如果我尝试使用我的浏览器(IE,Opera,Chrome)下载文件,则文件名将显示在filedialog中,因此必须将其保存在某处。 你能想象我能在哪里找到它吗? 编辑:我无法从URL中提取它,因为链接是由php生成的 http://www.example.com/download.php?id=10

获取Content-Disposition参数

如何使用WebClient获取从WebAPI控制器返回的Content-Disposition参数? WebApi控制器 [Route(“api/mycontroller/GetFile/{fileId}”)] public HttpResponseMessage GetFile(int fileId) { try { var file = GetSomeFile(fileId) HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StreamContent(new MemoryStream(file)); response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue(“attachment”); response.Content.Headers.ContentDisposition.FileName = file.FileOriginalName; /********* Parameter *************/ response.Content.Headers.ContentDisposition.Parameters.Add(new NameValueHeaderValue(“MyParameter”, “MyValue”)); return response; } catch(Exception ex) { return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex); } } 客户 void DownloadFile() { WebClient wc = […]

Content-Disposition标头中的Unicode

我正在使用在HttpHandler子项中实现的HttpContext对象来下载文件,当我在文件名中有非ascii字符时,它在IE中看起来很奇怪,而在Firefox中看起来很好。 以下是代码: – context.Response.ContentType = “.cs”; context.Response.AppendHeader(“Content-Length”, data.Length.ToString()); context.Response.AppendHeader(“Content-Disposition”, String.Format(“attachment; filename={0}”,filename)); context.Response.OutputStream.Write(data, 0, data.Length); context.Response.Flush(); 当我在文件名字段中提供”””””””””””””””””””””””””””””””””””””””””””””名字在firefox中看起来很好。 添加EncodingType和charset一直没用。 即它是’ß””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””’ Ô””””””””””””””””””””’ 任何想法如何解决这个问题?