ashx时“文档的顶层无效”的处理办法

来源:互联网 发布:织围巾 知乎 编辑:程序博客网 时间:2024/05/16 19:33

 解决的办法是
context.Response.ContentType = "text/plain";


把这行去掉或注释掉,看看这里有详解
http://dev.21tx.com/2005/02/01/12191.html

 

摘要如下:

 

Response.ContentType :控制输出的文件类型 

服务器送给客户端的数据包类型可以是text/html文本,也可以是gif/jpeg图形文件,所以每次传输前,我们都必须告知客户端将要传输的文件类型,一般默认情况下为“Text/Html”类型。
<% Response.ContentType = "text/HTML" %>
<% Response.ContentType = "image/GIF" %>
<% Response.ContentType = "image/JPEG" %>
<% Response.ContentType = "text/plain" %>
<% Response.ContentType = "image/JPEG" %>
<% Response.ContentType = "application/x-cdf" %>
用于作为文本内容返回而不是已解释的 HTML 语句
Response.ContentType = "text/plain"

你可以注意到:页面提供下载,页面中的ASP内容被解释执行了的

程序文件以XLS文件被提供下载
Response.ContentType = "application/vnd.ms-Excel"


实现歌曲连续播放
response.ContentType="audio/x-pn-realaudio" 

response.write 输出的时候,由于定义了response.ContentType 所以输出歌曲地址的时候会自动调用符合相应格式的软件来播放歌曲,不过前提是播放歌曲的软件必须先安装的。[讨论]Response.ContentType 控制输出文件类型(讨论下载文件问题)

…………………………