title: How to Make Very Simple ASP.Net Password Protected Page
body: <p>I am looking for a very simple solution to password protect an ASP.Net page. </p>
  
  <p>I found exactly what I am looking for <a href="http://support.microsoft.com/kb/301464" rel="noreferrer">here</a> but it is in ASP and I do not know the syntax to convert it to ASP.Net. </p>
  
  <p>It simply creates a temporary cookie that will expire as soon as they close their browser window.</p>
  
  <p>I am not looking to store the username / password in a db. I will manually change the password occasionally. </p>
  
  <p>Simply helping me convert the following code to ASP.Net would be wonderful!</p>
  
  <p>This goes on the logon.aspx page and pulls values from a form. </p>
  
  <pre><code>Username="Administrator"
  Password="Admin"
  Validated = "OK"
  
  if Strcomp(Request.Form("User"),Username,1)=0 AND Request.Form("password") = Password then
      Response.Cookies("ValidUser") = Validated
  
      If (Request.QueryString("from")&lt;&gt;"") then
          Response.Redirect Request.QueryString("from")
      else
        Response.Redirect "MyPage.aspx"
      End if    
  Else
      If Request.Form("User") &lt;&gt; "" then
          Response.Write "&lt;h3&gt;Authorization Failed.&lt;/h3&gt;" &amp; "&lt;br&gt;" &amp; _ "Please try again.&lt;br&gt;&amp;#xa0;&lt;br&gt;"
      End if
  End if
  </code></pre>
  
  <p>This goes on the password protected page to confirm the cookie was created. </p>
  
  <pre><code>Validated = "OK"
  
  if Request.Cookies("ValidUser") &lt;&gt; Validated then
  dim s
  s = "http://"
  s = s &amp; Request.ServerVariables("HTTP_HOST")
  s = s &amp; Request.ServerVariables("URL")
  
  if Request.QueryString.Count &gt; 0 THEN
      s = s &amp; "?" &amp; Request.QueryString 
  end if
  
  Response.Redirect "Logon.aspx"
  End if
  </code></pre>