Creating Expiring Web Pages :: Page A

This demo illustrates how to create an expiring Web page. Imagine that this page has a ton of legalese that you want to ensure that the user has read before progressing onto PageB.aspx.

Blah blah blah... boring legalese... READ IT ALL!

Source Code
<form runat="server">
  Blah blah blah... boring legalese... <b>READ IT ALL!</b>
  <asp:CheckBox runat="server" id="IHaveReadThis" Text="I Have Read this Page" />
  <asp:Label runat="server" id="ReadMeMsg" Visible="False" ForeColor="Red" Font-Italic="True">Please read this page and check this checkbox...</asp:Label>
  <br />
  <asp:Button OnClick="GotoPageB" Runat="server" id="btnGoToPageB" Text="Go to PageB.aspx" />

<script runat="server" language="VB">
  Sub GotoPageB(sender as Object, e as EventArgs)
    'Make sure the checkbox is checked
    If IHaveReadThis.Checked Then
      'Redirect user to URL
      Response.Redirect(CreateTamperProofURL("ExpiringDemoB.aspx", String.Empty, "Time=" & DateTime.Now.ToString("yyyyMMddHHmmss")))
      ReadMeMsg.Visible = True
    End If
  End Sub
'The secret salt...
Private Const SecretSalt = "H3#@*ALMLLlk31q4l1ncL#@RFHF#N3fNM><#WH$O@#!FN#LNl33N#LNFl#J#Y$#IOHhnf;;3qrthl3q"

Function CreateTamperProofURL(url as String, nonTamperProofParams as String, tamperProofParams as String) as String
  Dim tpURL as String = url
  If nonTamperProofParams.Length > 0 OrElse tamperProofParams.Length > 0 Then
    url &= "?"
  End If
  'Add on the tamper & non-tamper proof parameters, if any
  If nonTamperProofParams.Length > 0 then
    url &= nonTamperProofParams
    If tamperProofParams.Length > 0 Then url &= "&"
  End If
  If tamperProofParams.Length > 0 Then url &= tamperProofParams
  'Add on the tamper-proof digest, if needed
  If tamperProofParams.Length > 0 Then    
    url &= String.Concat("&Digest=", GetDigest(tamperProofParams)) 
  End If
  Return url
End Function

Function GetDigest(tamperProofParams as String) as String
  Dim Digest as String = String.Empty
  Dim input as String = String.Concat(SecretSalt, tamperProofParams, SecretSalt)
  'The array of bytes that will contain the encrypted value of input
  Dim hashedDataBytes As Byte()

  'The encoder class used to convert strPlainText to an array of bytes
  Dim encoder As New System.Text.UTF8Encoding

  'Create an instance of the MD5CryptoServiceProvider class
  Dim md5Hasher As New System.Security.Cryptography.MD5CryptoServiceProvider

  'Call ComputeHash, passing in the plain-text string as an array of bytes
  'The return value is the encrypted value, as an array of bytes
  hashedDataBytes = md5Hasher.ComputeHash(encoder.GetBytes(input))

  'Base-64 Encode the results and strip off ending '==', if it exists
  Digest = Convert.ToBase64String(hashedDataBytes).TrimEnd("=".ToCharArray())
  Return Digest
End Function  

[Back to the article...]