从Respose.WriteFile()/ Response.ContentType显示广告内容 [英] Displaying ad content from Respose.WriteFile()/ Response.ContentType

查看:86
本文介绍了从Respose.WriteFile()/ Response.ContentType显示广告内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个人怎么会显示任何从动态aspx页面添加内容?目前,我正在使用System.Web.HttpResponsePage.Response编写存储在Web服务器的Web请求的文件中。

How would one display any add content from a "dynamic" aspx page? Currently I am working on using the System.Web.HttpResponse "Page.Response" to write a file that is stored on a web server to a web request.

这会让人们打一个网址的类型 http://www.foo.com?Image=test.jpg 并在其浏览器中的图像显示。所以,当你知道这是围绕使用Response.ContentType的。

This would allow people to hit a url to the type http://www.foo.com?Image=test.jpg and have the image display in their browser. So as you may know this revolves around the use of Response.ContentType.

通过使用

Response.ContentType = "application/octet-stream";



我能够显示类型GIF / JPEG / PNG图像(所有我迄今测试) ,位试图显示.swf文件或.ico文件给了我一个可爱的小错误。

I am able to display images of type gif/jpeg/png (all i have tested so far), bit trying to display .swf or .ico files gives me a nice little error.

使用

Response.ContentType = "application/x-shockwave-flash";



我可以让Flash文件播放,但随后的图像混乱。

I can get flash files to play, but then the images are messed.

让我怎么容易选择的contentType?

So how do i easily choose the contenttype?

推荐答案

这是丑陋的,但最好的方法是看该文件,并设置内容类型的适当内容:

This is ugly, but the best way is to look at the file and set the content type as appropriate:

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; 
}

这篇关于从Respose.WriteFile()/ Response.ContentType显示广告内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆