如何从"动态"aspx页面显示任何添加内容?目前我正在使用System.Web.HttpResponse"Page.Response"将存储在Web服务器上的文件写入Web请求.
这将允许人们点击http://www.foo.com?Image=test.jpg类型的URL 并在他们的浏览器中显示图像.因此,您可能知道这围绕着Response.ContentType的使用.
通过使用
Response.ContentType = "application/octet-stream";
Run Code Online (Sandbox Code Playgroud)
我能够显示类型为gif/jpeg/png的图像(到目前为止我已经测试过了),试图显示.swf或.ico文件的位给了我一个不错的小错误.
运用
Response.ContentType = "application/x-shockwave-flash";
Run Code Online (Sandbox Code Playgroud)
我可以播放Flash文件,但随后图像混乱.
那么我如何轻松选择内容类型?
这很难看,但最好的方法是查看文件并根据需要设置内容类型:
switch ( fileExtension )
{
case "pdf": Response.ContentType = "application/pdf"; break;
case "swf": Response.ContentType = "application/x-shockwave-flash"; break;
case "gif": Response.ContentType = "image/gif"; break;
case "jpeg": Response.ContentType = "image/jpg"; break;
case "jpg": Response.ContentType = "image/jpg"; break;
case "png": Response.ContentType = "image/png"; break;
case "mp4": Response.ContentType = "video/mp4"; break;
case "mpeg": Response.ContentType = "video/mpeg"; break;
case "mov": Response.ContentType = "video/quicktime"; break;
case "wmv":
case "avi": Response.ContentType = "video/x-ms-wmv"; break;
//and so on
default: Response.ContentType = "application/octet-stream"; break;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18235 次 |
| 最近记录: |