ASP.Net将文件下载到客户端浏览器
发布时间:2020-12-16 00:29:48 所属栏目:asp.Net 来源:网络整理
导读:我正在编写一个简单的测试页面,在按钮点击下载文本文件到浏览器。我得到一个非常奇怪的错误,我从来没有见过。有什么想法吗? 错误发生在’Response.End();’并且文件永远不会访问客户端浏览器 码: string filePath = "C:test.txt"; FileInfo file = new
我正在编写一个简单的测试页面,在按钮点击下载文本文件到浏览器。我得到一个非常奇怪的错误,我从来没有见过。有什么想法吗?
错误发生在’Response.End();’并且文件永远不会访问客户端浏览器 码: string filePath = "C:test.txt"; FileInfo file = new FileInfo(filePath); if (file.Exists) { Response.ClearContent(); Response.AddHeader("Content-Disposition","attachment; filename=" + file.Name); Response.AddHeader("Content-Length",file.Length.ToString()); Response.ContentType = "text/plain"; Response.TransmitFile(file.FullName); Response.End(); } 错误:
解决方法
尝试改变它。
Response.Clear(); Response.ClearHeaders(); Response.ClearContent(); Response.AddHeader("Content-Disposition","attachment; filename=" + file.Name); Response.AddHeader("Content-Length",file.Length.ToString()); Response.ContentType = "text/plain"; Response.Flush(); Response.TransmitFile(file.FullName); Response.End(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET MVC 4和Razor 2:View引擎不再支持xml?
- asp.net – 脚本管理器和工具包脚本管理器之间的区别
- asp.net-mvc – Razor中的Direct Model.Property与Html Hel
- asp.net-core – 哪些.NET框架版本支持.NET Framework(CLR)
- asp.net – 如何打破VB.NET中的“if”块
- asp.net-mvc-4 – URL以’/’结尾时的服务器错误
- 在使用ASP.NET MVC的Action方法中使用哪种重定向方法进行SE
- asp.net – SOAP与HTTP
- asp.net-mvc – 构建与数据格式分离的ASP.NET MVC REST API
- asp.net-mvc-2 – ASP.MVC 2 RTM ModelState Id属性的错误
推荐文章
站长推荐
热点阅读