Interacting With Cookies From PowerShell ASP

PowerShell ASP works in much the same way that ASP.NET would. Interacting with cookies is no different. Below is an example showing how to display and create cookies in the user's browser:

<html>
    <head>        
        <link href="stylesheet.css" rel="stylesheet" type="text/css"></link>
    </head>
    <body>
      <%
        if($Request.RequestType -eq "POST")
        { 
          #Check the cookies in the request.
          $Request.Cookies.AllKeys | % { echo "$_ : $($Request.Cookies[$_].Value)<br>" }
        }
        else
        {
          #Create a cookie
          $cookie = New-Object -TypeName System.Web.HttpCookie -ArgumentList @("myCookie","myCookieValue")
          
          #Add it to the cookies collection in the response
          $Response.Cookies.Add($cookie)
          %>
          <form action="" method="POST">
            <button name="seeCookies" value="seeCookies">Check Cookies.</button>
          </form>
          <%
        }
      %>
    </body>
</html>

We appreciate your feedback.  If you have any questions, comments, or suggestions about this article please contact our support team at kb@nsoftware.com.