Here, There, and Back Again: Maintaining State Across Domains (cont.)

Technique 2: Where Did I Go Today?
Bouncing users across time and space and multiple subdomains can bewilder developers, to say nothing of what it can do to site visitors if not done properly. In the DevX WindowsXP Developer Center (http://www.devx.com/whistler) DevX uses an authentication process that essentially logs users into three different systems simultaneously as it navigates a decision tree. That’s a lot of redirects. I got caught in a few infinite loops before I thought to anchor myself with a simple ReturnURL cookie.

Before you kick off a series of redirects, save the final destination page in a cookie. The following example describes a loop across subdomains where users ultimately return to the page they started from. Setting the .domain property makes this work over multiple subdomains.

   ' Set the domain for the cookie
   Response.Cookies("MainCookie").Domain = "mycompany.com"
   ' Calculate the current page, adding a QueryString if it exists
   strThisPage = "http://" & Request.ServerVariables("SERVER_NAME") & _
      Request.ServerVariables("SCRIPT_NAME")
   If Request.ServerVariables("QUERY_STRING") <> "" then
      strThisPage = strThisPage & "?" & _
         Request.ServerVariables("QUERY_STRING")
   End If
   ' Set the CustomerID and Return URL within the same cookie
   Response.Cookies("MainCookie")("CustomerID") = intCustomerID
   Response.Cookies("MainCookie")("ReturnUrl") = strThisPage
   ' Set the expiry date for 1 day from now
   Response.Cookies("MainCookie").Expires = DateAdd("d", 1, Now)
   'Redirect the user to the next step in the process
   Response.Redirect("http://members.mycompany.com/reg/step2.asp")

Then, after doing that voodoo you do so well, send the user to a universal redirect page that gives him one last punt to the ReturnUrl. Here’s the crucial code snippet from returnurl.asp:

   strReturnUrl=Request.Cookies("MainCookie")("ReturnUrl")
   ' Check for an unassigned ReturnURL, just in case
   If strReturnUrl = "" then strReturnUrl = _
      "http://www.mycompany.com/default.asp"
   Response.Redirect(strReturnUrl)


Back

Next

Technique 1: Master of your .domain
Technique 2: Where Did I Go Today?
Technique 3: The Boomerang





 TALK BACK
Have you ever used the techniques described in this article? Are you using other methods for maintaining user state information across domains? Join the DevX ASP community at devx.web.asp to get answers, make comments, or help others with their problems.
Click here to Join
Maintaining Session State on Your Web Farm

Maintaining State Within a Website (w/o Cookies or Server-side Scripting)

Cookies Across Domains

Maintaining Session State & Sharing Data across Servers, Domains & the Entire Internet

The Unofficial Cookie FAQ





 
Sponsored Links

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map
Jupiterweb networks

internet.comearthweb.comDevx.comClickZ

Search Jupiterweb:

Jupitermedia Corporation has four divisions:
JupiterWeb, JupiterResearch, JupiterEvents, and JupiterImages

Copyright 2004 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Jupitermedia Corporate Info | Newsletters | Tech Jobs | E-mail Offers

Copyright Information/Privacy Statement