ASP.NET Intrinsic Objects

Besides running standard PowerShell scripts, you can interact with the HTTP runtime through the use of the ASP.NET intrinsic objects like HttpRequest and HttpResponse. Because of the threading model used by PowerShell, those objects are not directly accessible through HttpContext.Runtime.

  • $Request: Contains the HttpRequest object.
  • $Server: Contains the HttpServerUtility object.
  • $Session: Contains the HttpSessionState object.
  • $Application: Contains the HttpApplicationState object.
  • $Response: Contains the HttpResponse object. You can write directly to the response stream from code if you want, or you can use write-host and friends as well.
  • $Cache: Contains the HttpCache object.
  • $Context: The HttpContext object associated with the current request.

These objects are used in exactly the same way as in regular ASP.NET applications.

Here is an example script that will dump all the values in the HttpRequest object to a simple HTML page:

  <% $request.params | %{
      write-output "$_ = $($request[$_])<br/>"
  } %>

You can see this sample uses the PowerShell Write-Output cmdlet to generate the output

Copyright (c) 2022 /n software inc. - All rights reserved.
PowerShell Server 2020 - Version 20.0 [Build 8165]