Name

ContentType

Synopsis

String = Response.ContentType
Response.ContentType = String

Returns or sets a String containing the MIME type of the current response. This allows you to retrieve or set the value of the HTTP Content-Type response header.

Parameters

String

A string variable to receive or set the content type. The default is “text/html.”

Example

The following example displays the current MIME content type in the client browser.

Sub Page_Load(  )
   Message.Text = "Current content type is " & _
      Response.ContentType & "<br/>" 
End Sub

Notes

The ContentType property is very important, since it enables you to send content to the client browser other than the default HTML. For example, if you want to use the Response.BinaryWrite method to send binary image data to the client browser, you must also set the ContentType property to the appropriate MIME type (“image/jpg” or “image/gif”, for example). See the BinaryWrite example for an example of how this is done.

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.