Name
ContentType
Synopsis
stringvar = Request.ContentType
Returns a String containing the MIME type of the current client request. On GET requests, this property may return an empty string.
Parameters
-
stringvar
A String variable to receive the content type.
Example
The example shows how you can take different actions in your page, depending on the ContentType of the request:
Sub Page_Load( ) Dim ct As String ct = Request.ContentType If ct = "application/x-www-form-urlencoded" Then 'Process form input Message.Text = "Form data was submitted." Else Message.Text = "Content Type of request is: " & ct End If End Sub
The following code can be used to post to the example page:
<html> <head> <title>Submit a named parameter via POST</title> </head> <body> <form id="form1" action="ContentType.aspx" method="POST"> <h3>Name:</h3> <input type="text" name="name"> <input type="submit"> </form> </body> </html>
Notes
One potential use for this property is to ensure that the content type of the request is what you expect it to be. This can help avoid wasting processor time with invalid requests and prevent malicious users from attempting to forge requests to your application that send unexpected content.
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.