DekGenius.com
[ Team LiB ] Previous Section Next Section

16.4 Methods Reference

BinaryRead

byteArray = Request.BinaryRead(byteCount)

Returns a byte array containing the number of bytes specified by the byteCount argument.

Parameters

byteArray

An Array variable of type Byte to receive the specified number of bytes from the method.

byteCount

An integer specifying the number of bytes to return.

Notes

This method provides backward compatibility with classic ASP applications. For new development, using other means (such as the Files collection, etc.) is preferable to achieve the results that this method was used for.

MapPath

stringvar = Request.MapPath(virtualPath)
stringvar = Request.MapPath(virtualPath, _
  baseVirtualDirectory, allowCrossMapping)

The MapPath method, which the Server object exposed in classic ASP, allows you to retrieve a physical path on the server for a provided virtual path. In ASP.NET, this method is overloaded, meaning that it can be called with two different sets of arguments, as shown in the previous code. The first style, which is the same as in classic ASP, simply passes in a String containing the virtual path to be mapped. The second adds the baseVirtualDirectory argument, which specifies a base from which to resolve relative paths, and the allowCrossMapping argument, which allows you to map virtual paths that belong to other applications.

Parameters

stringvar

A String variable to receive the mapped physical path.

virtualPath

A String argument containing the virtual path to map.

baseVirtualDirectory

A String argument containing a base path to be used for resolving relative paths.

allowCrossMapping

A Boolean argument specifying whether paths can be mapped across applications.

Example

The example maps the path of the .NET Framework SDK samples' /QuickStart directory and writes the result to the browser:

Sub Page_Load( )
   Dim VirPath, PhysPath, BasePath As String
   Dim BoolCross As Boolean = True
  
   VirPath = "/QuickStart"
   BasePath = ""
  
   Message.Text = Request.MapPath(VirPath, BasePath, BoolCross)
End Sub

Notes

In the previous example, if we had set the BoolCross variable to False and called the example code from outside the QuickStart application, an HttpException would be thrown, since this argument must be set to True to map paths across applications.

SaveAs

Request.SaveAs(filename, includeHeaders)

Saves the current HTTP request to disk, using the filename argument as the path and filename under which to save the request.

Parameters

filename

A String argument containing the path and filename under which the request should be saved.

includeHeaders

A Boolean argument indicating whether to save the HTTP header information as part of the request. Note that unless this is a POST request (or other request type with a request body), no information is saved if this argument is set to False.

Example

The example writes the HTTP request headers to the browser (for comparison purposes) and then saves the current request both with and without header information:

Sub Page_Load( )
   Message.Text = Request.Headers
  
   ' Save HTTP Request and Headers to a file
   Request.SaveAs((Request.PhysicalApplicationPath & _
      "HTTPRequest.txt"), True)
   ' Save HTTP Request to a file
   Request.SaveAs((Request.PhysicalApplicationPath & _
      "HTTPRequest_NoHeaders.txt"), False)
End Sub

Notes

This method can be very useful when debugging because it allows you to look at all the information sent in a given request (which is particularly useful in POST requests).

    [ Team LiB ] Previous Section Next Section