ASP.NET 中 ContentType 类型

吕扬
2023-12-01

ASP.NET 中 ContentType 类型

在ASP.NET中使用Response.ContentType="类型名";来确定输出格式

不同的ContentType 会影响客户端所看到的效果.默认的ContentType为 text/html 也就是网页格式.
代码如:
<% response.ContentType ="text/html" %> 
<!--#i nclude virtual="/ContentType.html" -->
显示的为网页,而
<% response.ContentType ="text/plain" %> 
<!--#i nclude virtual="/sscript/ContentType.html" -->
则会显示html原代码.

以下为一些常用的 ContentType
GIF images 
<% response.ContentType ="image/gif" %> 
<!--#i nclude virtual="/myimage.gif" -->
JPEG images 
<% response.ContentType ="image/jpeg" %> 
<!--#i nclude virtual="/myimage.jpeg" --> 
TIFF images 
<% response.ContentType ="image/tiff" %> 
<!--#i nclude virtual="/myimage.tiff" --> 
MICROSOFT WORD document 
<% response.ContentType ="application/msword" %> 
<!--#i nclude virtual="/myfile.doc" -->
RTF document 
<% response.ContentType ="application/rtf" %> 
<!--#i nclude virtual="/myfile.rtf" -->
MICROSOFT EXCEL document 
<% response.ContentType ="application/x-excel" %> 
<!--#i nclude virtual="/myfile.xls" -->
MICROSOFT POWERPOINT document 
<% response.ContentType ="application/ms-powerpoint" %> 
<!--#i nclude virtual="/myfile.pff" -->
PDF document 
<% response.ContentType ="application/pdf" %> 
<!--#i nclude virtual="/myfile.pdf" -->
ZIP document 
<% response.ContentType ="application/zip" %> 
<!--#i nclude virtual="/myfile.zip" -->

RAR document

Response.ContentType = "application/x-msdownload ; Charset=utf-8";   
Response.AddHeader("Content-Disposition", "attachment; filename=...");
下面是更详细的ContentType
前边为类型, 后边为相应Type,只需要TYPE就可以.例如:'ez' => 'application/andrew-inset', 

 

Application Type 

文件扩展名Content-Type(Mime-Type)描述
.application/x- 
.*application/octet-stream二进制流,不知道下载文件类型
.pdfapplication/pdfPDF(Portable Document Format的简称,意为“便携式文件格式”)
.aiapplication/postscriptPostScript(PS)是主要用于电子产业和桌面出版领域的一种页面描述语言和编程语言。
.xmlapplication/atom+xmlAtom feeds
.jsapplication/ecmascript相当于application/javascript但是严格的处理规则
.ediapplication/EDI-X12EDI ANSI ASC X12数据
.ediapplication/EDIFACTEDI EDIFACT数据
.jsonapplication/jsonJSON(JavaScript Object Notation)
.jsapplication/javascriptECMAScript/JavaScript(相当于application/ecmascript但是宽松的处理规则)
.oggapplication/oggOgg, 视频文件格式
.rdfapplication/rdf+xml资源描述框架(Resource Description Framework,缩写 RDF),是万维网联盟(W3C)提出的一组标记语言的技术标准,以便更为丰富地描述和表达网络资源的内容与结构。
.xmlapplication/rss+xmlRSS(Really Simple Syndication,简易信息聚合)是一种消息来源格式规范,用以聚合经常发布更新数据的网站,例如博客文章、新闻、音频或视频的网摘
.xmlapplication/soap+xml简单对象访问协议(SOAP,全写为Simple Object Access Protocol)是交换数据的一种协议规范,使用在计算机网络Web服务(web service)中,交换带结构信息。
.woffapplication/font-woffWeb开放字体格式(Web Open Font Format,简称WOFF)是一种网页所采用的字体格式标准。(推荐使用;使用application/x-font-woff直到它变为官方标准)
.xhtmlapplication/xhtml+xml可扩展超文本标记语言(eXtensible HyperText Markup Language,XHTML),是一种标记语言,表现方式与超文本标记语言(HTML)类似,不过语法上更加严格。
.xmlapplication/xml可扩展标记语言(英语:eXtensible Markup Language,简称: XML),是一种标记语言。
.dtdapplication/xml-dtdXML文件的文件型别定义(Document Type Definition)可以看成一个或者多个XML文件的模板,在这里可以定义XML文件中的元素、元素的属性、元素的排列方式、元素包含的内容等等。
.xmlapplication/xop+xml二进制优化封装协议(Xmlbinary Optimized Packaging)
.zipapplication/zipZIP压缩文件
.gzipapplication/gzipGzip是若干种文件压缩程序的简称,通常指GNU计划的实现,此处的gzip代表GNU zip。
.xlsapplication/x-xlsXLS 就是 Microsoft Excel 工作表,是一种非常常用的电子表格格式。
.001application/x-001 
.301application/x-301 
.906application/x-906 
.a11application/x-a11 
.awfapplication/vnd.adobe.workflow 
.bmpapplication/x-bmp 
.c4tapplication/x-c4t 
.calapplication/x-cals 
.cdfapplication/x-netcdf 
.celapplication/x-cel 
.cg4application/x-g4 
.citapplication/x-cit 
.botapplication/x-bot 
.c90application/x-c90 
.catapplication/vnd.ms-pki.seccat 
.cdrapplication/x-cdr 
.cerapplication/x-x509-ca-cert 
.cgmapplication/x-cgm 
.cmxapplication/x-cmx 
.crlapplication/pkix-crl 
.csiapplication/x-csi 
.cutapplication/x-cut 
.dbmapplication/x-dbm 
.cmpapplication/x-cmp 
.cotapplication/x-cot 
.crtapplication/x-x509-ca-cert 
.dbfapplication/x-dbf 
.dbxapplication/x-dbx 
.dcxapplication/x-dcx 
.dgnapplication/x-dgn 
.dllapplication/x-msdownload 
.dotapplication/msword 
.derapplication/x-x509-ca-cert 
.dibapplication/x-dib 
.docapplication/msword 
.drwapplication/x-drw 
.dwfapplication/x-dwf 
.dxbapplication/x-dxb 
.ednapplication/vnd.adobe.edn 
.dwgapplication/x-dwg 
.dxfapplication/x-dxf 
.emfapplication/x-emf 
.epiapplication/x-epi 
.epsapplication/postscript 
.exeapplication/x-msdownload 
.fdfapplication/vnd.fdf 
.epsapplication/x-ps 
.etdapplication/x-ebx 
.fifapplication/fractals 
.frmapplication/x-frm 
.gbrapplication/x-gbr 
.g4application/x-g4 
.gl2application/x-gl2 
.hglapplication/x-hgl 
.hpgapplication/x-hpgl 
.hqxapplication/mac-binhex40 
.htaapplication/hta 
.gp4application/x-gp4 
.hmrapplication/x-hmr 
.hplapplication/x-hpl 
.hrfapplication/x-hrf 
.icbapplication/x-icb 
.icoapplication/x-ico 
.ig4application/x-g4 
.iiiapplication/x-iphone 
.insapplication/x-internet-signup 
.iffapplication/x-iff 
.igsapplication/x-igs 
.imgapplication/x-img 
.ispapplication/x-internet-signup 
.jpeapplication/x-jpe 
.jsapplication/x-javascript 
.jpgapplication/x-jpg 
.larapplication/x-laplayer-reg 
.latexapplication/x-latex 
.lbmapplication/x-lbm 
.lsapplication/x-javascript 
.ltrapplication/x-ltr 
.manapplication/x-troff-man 
.mdbapplication/msaccess 
.macapplication/x-mac 
.mdbapplication/x-mdb 
.mfpapplication/x-shockwave-flash 
.miapplication/x-mi 
.milapplication/x-mil 
.mochaapplication/x-javascript 
.mpdapplication/vnd.ms-project 
.mppapplication/vnd.ms-project 
.mptapplication/vnd.ms-project 
.mpwapplication/vnd.ms-project 
.mpxapplication/vnd.ms-project 
.mxpapplication/x-mmxp 
.nrfapplication/x-nrf 
.outapplication/x-out 
.p12application/x-pkcs12 
.p7capplication/pkcs7-mime 
.p7rapplication/x-pkcs7-certreqresp 
.pc5application/x-pc5 
.pclapplication/x-pcl 
.pdxapplication/vnd.adobe.pdx 
.pglapplication/x-pgl 
.pkoapplication/vnd.ms-pki.pko 
.p10application/pkcs10 
.p7bapplication/x-pkcs7-certificates 
.p7mapplication/pkcs7-mime 
.p7sapplication/pkcs7-signature 
.pciapplication/x-pci 
.pcxapplication/x-pcx 
.pdfapplication/pdf 
.pfxapplication/x-pkcs12 
.picapplication/x-pic 
.plapplication/x-perl 
.pltapplication/x-plt 
.pngapplication/x-png 
.ppaapplication/vnd.ms-powerpoint 
.ppsapplication/vnd.ms-powerpoint 
.pptapplication/x-ppt 
.prfapplication/pics-rules 
.prtapplication/x-prt 
.psapplication/postscript 
.pwzapplication/vnd.ms-powerpoint 
.raaudio/vnd.rn-realaudioRealAudio是一种由RealNetworks发展的RealMedia多媒体音频文件格式,仅指RealPlayer中能够识别的音频文件,也可以理解为real格式的音频文件。
.rasapplication/x-ras 
.potapplication/vnd.ms-powerpoint 
.ppmapplication/x-ppm 
.pptapplication/vnd.ms-powerpoint 
.prapplication/x-pr 
.prnapplication/x-prn 
.psapplication/x-ps 
.ptnapplication/x-ptn 
.redapplication/x-red 
.rjsapplication/vnd.rn-realsystem-rjs 
.rlcapplication/x-rlc 
.rmapplication/vnd.rn-realmedia 
.ratapplication/rat-file 
.recapplication/vnd.rn-recording 
.rgbapplication/x-rgb 
.rjtapplication/vnd.rn-realsystem-rjt 
.rleapplication/x-rle 
.rmfapplication/vnd.adobe.rmf 
.rmjapplication/vnd.rn-realsystem-rmj 
.rmpapplication/vnd.rn-rn_music_package 
.rmvbapplication/vnd.rn-realmedia-vbr 
.rnxapplication/vnd.rn-realplayer 
.rpmaudio/x-pn-realaudio-plugin 
.rmsapplication/vnd.rn-realmedia-secure 
.rmxapplication/vnd.rn-realsystem-rmx 
.rsmlapplication/vnd.rn-rsml 
.rtfapplication/msword 
.rvvideo/vnd.rn-realvideo 
.satapplication/x-sat 
.sdwapplication/x-sdw 
.slbapplication/x-slb 
.rtfapplication/x-rtf 
.samapplication/x-sam 
.sdpapplication/sdp 
.sitapplication/x-stuffit 
.sldapplication/x-sld 
.smiapplication/smil 
.smkapplication/x-smk 
.smilapplication/smil 
.spcapplication/x-pkcs7-certificates 
.splapplication/futuresplash 
.ssmapplication/streamingmedia 
.stlapplication/vnd.ms-pki.stl 
.sstapplication/vnd.ms-pki.certstore 
.tdfapplication/x-tdf 
.tgaapplication/x-tga 
.styapplication/x-sty 
.swfapplication/x-shockwave-flash 
.tg4application/x-tg4 
.tifapplication/x-tif 
.vdxapplication/vnd.visio 
.vpgapplication/x-vpeg005 
.vsdapplication/x-vsd 
.vstapplication/vnd.visio 
.vswapplication/vnd.visio 
.vtxapplication/vnd.visio 
.torrentapplication/x-bittorrent 
.vdaapplication/x-vda 
.vsdapplication/vnd.visio 
.vssapplication/vnd.visio 
.vstapplication/x-vst 
.vsxapplication/vnd.visio 
.wb1application/x-wb1 
.wb3application/x-wb3 
.wizapplication/msword 
.wk4application/x-wk4 
.wksapplication/x-wks 
.wb2application/x-wb2 
.wk3application/x-wk3 
.wkqapplication/x-wkq 
.wmfapplication/x-wmf 
.wmdapplication/x-ms-wmd 
.wp6application/x-wp6 
.wpgapplication/x-wpg 
.wq1application/x-wq1 
.wriapplication/x-wri 
.wsapplication/x-ws 
.wmzapplication/x-ms-wmz 
.wpdapplication/x-wpd 
.wplapplication/vnd.ms-wpl 
.wr1application/x-wr1 
.wrkapplication/x-wrk 
.ws2application/x-ws 
.xdpapplication/vnd.adobe.xdp 
.xfdapplication/vnd.adobe.xfd 
.xfdfapplication/vnd.adobe.xfdf 
.xlsapplication/vnd.ms-excel 
.xwdapplication/x-xwd 
.sisapplication/vnd.symbian.install 
.x_tapplication/x-x_t 
.apkapplication/vnd.android.package-archive 
.x_bapplication/x-x_b 
.sisxapplication/vnd.symbian.install 
.ipaapplication/vnd.iphone 
.xapapplication/x-silverlight-app 
.xlwapplication/x-xlw 
.xplaudio/scpls 
.anvapplication/x-anv 
.uinapplication/x-icq 

 

Text Type 

文件扩展名Content-Type(Mime-Type)描述
.323text/h323 
.biztext/xml 
.cmltext/xml 
.asatext/asa 
.asptext/asp 
.csstext/css层叠样式表(英语:Cascading Style Sheets,简写CSS),又称串样式列表、层次结构式样式表文件,一种用来为结构化文档(如HTML文档或XML应用)添加样式(字体、间距和颜色等)的计算机语言,由W3C定义和维护。
.csvtext/csv逗号分隔值(Comma-Separated Values,CSV,有时也称为字符分隔值,因为分隔字符也可以不是逗号),其文件以纯文本形式存储表格数据(数字和文本)。
.dcdtext/xml 
.dtdtext/xml 
.enttext/xml 
.fotext/xml 
.htctext/x-component 
.htmltext/html 
.htxtext/html 
.htmtext/html 
.htttext/webviewhtml 
.jsptext/html 
.mathtext/xml 
.mmltext/xml 
.mtxtext/xml 
.plgtext/html 
.rdftext/xml 
.rttext/vnd.rn-realtext 
.soltext/plain 
.spptext/xml 
.stmtext/html 
.svgtext/xml 
.tldtext/xml 
.txttext/plain纯文字内容
.ulstext/iuls 
.vmltext/xml 
.tsdtext/xml 
.vcftext/x-vcard 
.vxmltext/xml 
.wmltext/vnd.wap.wml 
.wsdltext/xml 
.wsctext/scriptlet 
.xdrtext/xml 
.xqltext/xml 
.xsdtext/xml 
.xslttext/xml 
.xmltext/xml 
.xqtext/xml 
.xquerytext/xml 
.xsltext/xml 
.xhtmltext/html 
.odctext/x-ms-odc 
.r3ttext/vnd.rn-realtext3d 
.sortext/plain 

 

Audio Type 

文件扩展名Content-Type(Mime-Type)描述
.acpaudio/x-mei-aac 
.aifaudio/aiff 
.aiffaudio/aiff 
.aifcaudio/aiff 
.auaudio/basic 
.la1audio/x-liquid-file 
.lavsaudio/x-liquid-secure 
.lmsffaudio/x-la-lms 
.m3uaudio/mpegurl 
.midiaudio/mid 
.midaudio/mid 
.mp2audio/mp2 
.mp3audio/mp3 
.mp4audio/mp4MP4,全称MPEG-4 Part 14,是一种使用MPEG-4的多媒体计算机文件格式,扩展名为.mp4,以存储数字音频及数字视频为主。
.mndaudio/x-musicnet-download 
.mp1audio/mp1 
.mnsaudio/x-musicnet-stream 
.mpgaaudio/rn-mpeg 
.plsaudio/scpls 
.ramaudio/x-pn-realaudio 
.rmiaudio/mid 
.rmmaudio/x-pn-realaudio 
.sndaudio/basic 
.wavaudio/wav 
.waxaudio/x-ms-wax 
.wmaaudio/x-ms-wma 

 

Video Type 

文件扩展名Content-Type(Mime-Type)描述
.asfvideo/x-ms-asf 
.asxvideo/x-ms-asf 
.avivideo/avi 
.IVFvideo/x-ivf 
.m1vvideo/x-mpeg 
.m2vvideo/x-mpeg 
.m4evideo/mpeg4 
.movievideo/x-sgi-movie 
.mp2vvideo/mpeg 
.mp4video/mpeg4MP4,全称MPEG-4 Part 14,是一种使用MPEG-4的多媒体计算机文件格式,扩展名为.mp4,以存储数字音频及数字视频为主。
.mpavideo/x-mpg 
.mpevideo/x-mpeg 
.mpgvideo/mpg 
.mpegvideo/mpg 
.mpsvideo/x-mpeg 
.mpvvideo/mpg 
.mpv2video/mpeg 
.wmvideo/x-ms-wm 
.wmvvideo/x-ms-wmv 
.wmxvideo/x-ms-wmx 
.wvxvideo/x-ms-wvx 

 

Image Type 

文件扩展名Content-Type(Mime-Type)描述
.tifimage/tiff标签图像文件格式(Tagged Image File Format,简写为TIFF)是一种主要用来存储包括照片和艺术图在内的图像的文件格式。它最初由Aldus公司与微软公司一起为PostScript打印开发。
.faximage/fax 
.gifimage/gif图像互换格式(GIF,Graphics Interchange Format)是一种位图图形文件格式,以8位色(即256种颜色)重现真彩色的图像。
.icoimage/x-icon 
.jfifimage/jpeg 
.jpeimage/jpeg 
.jpegimage/jpegJPEG是一种针对相片图像而广泛使用的一种有损压缩标准方法。
.jpgimage/jpeg 
.netimage/pnetvue 
.pngimage/png便携式网络图形(Portable Network Graphics,PNG)是一种无损压缩的位图图形格式,支持索引、灰度、RGB三种颜色方案以及Alpha通道等特性。
.rpimage/vnd.rn-realpix 
.tifimage/tiff 
.tiffimage/tiff 
.wbmpimage/vnd.wap.wbmp 

 

Message Type 

文件扩展名Content-Type(Mime-Type)描述
.emlmessage/rfc822 
.mhtmessage/rfc822 
.mhtmlmessage/rfc822 
.nwsmessage/rfc822 

 

Drawing Type 

文件扩展名Content-Type(Mime-Type)描述
.907drawing/907 
.slkdrawing/x-slk 
.topdrawing/x-top 

 

Java Type 

文件扩展名Content-Type(Mime-Type)描述
.classjava/* 
.javajava/* 

 

Other Type 

文件扩展名Content-Type(Mime-Type)描述
.dwfModel/vnd.dw

 

输出页面(尚未验证)

private void Page_Load(object sender, System.EventArgs e)
{
   try
      {
         string id = Request.QueryString["id"];

         int ID = Int32.Parse(id);

         byte[] imagebyte = //Get image data by image’s ID             

         Response.ContentType = "image/gif"; 

         Response.BinaryWrite( imagebyte );
       }

  catch(Exception Error)
       {
           Response.Write(Error.Message);

       }   
}

 

posted @ 2018-01-17 11:44 wuling129 阅读(...) 评论(...) 编辑 收藏

 类似资料: