
ContentType | 327
HttpRequest
Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Example
This example demonstrates how to display the length of the current request in the
browser:
Sub Page_Load( )
Dim length As Integer
length = Request.ContentLength
Message.Text = "Length of request was: " & length & " bytes."
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="ContentLength.aspx" method="POST">
<h3>Name:</h3>
<input type="text" name="name">
<input type="submit">
</form>
</body>
</html>
Notes
You can use this property to test the length of content posted via a POST request
before acting on that content. For example, if your page receives files from a file
input field, you could check the ContentLength property before saving or
processing the uploaded file to prevent users from uploading files greater than a
specific size. Note that in cases when you receive multiple form fields, you can
get more specific data on the size of an uploaded file by referring to the Posted-
File.ContentLength property of an HtmlInputFile control used for submitting
files.
ContentType
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. ...