|
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)
|
 |
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.
|
|
|
|
|
|
|