Forum Moderators: open

Message Too Old, No Replies

ASP Redirect Question

Keeping form data on redirect

         

MozMan

8:06 pm on Aug 25, 2004 (gmt 0)

10+ Year Member



Can anyone tell me if there is a good way to perform a response.redirect without losing what is in the form collection?

Here is my problem, we are moving to SSL, and I want to write a redirect in my global.asa to take anyone who comes in using http and move them to https. The problem is that some of my customers have forms on their intranets that pass to me login data, so that their employees don't have to login to my site after already having logged into their own. So, to give all of my customers time to update their form actions, I'd like to perform the redirect and pass along the data. I tried using server.transfer, but it won't let me transfer to an absolute url (including the https), so I have to user response.redirect... I can capture the form data, I just don't know how to put it back in the form collection for the redirect. any help would be appreciated.

-Moz

Xoc

4:29 am on Aug 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No. Because a Response.Redirect reports a 302 error to the browser, with the url of the new resource. It is then up to the browser to then do a GET to the new resource. In the process the form variables are lost.

You could store the stuff in the form variable into Session variables, then do the Response.Redirect, then pull them back out after the redirect.

digitalv

4:39 am on Aug 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could store the stuff in the form variable into Session variables, then do the Response.Redirect, then pull them back out after the redirect.

This is the best way to do it, but if for some reason you can't do a session (if the user has cookies blocked, for example, you won't be able to set/retrieve session variables) there is another method: Encrypt the information using Base64 or some other simple encryption and response.redirect with the data in the querystring. Something like this in your redirect page should do the trick:


FOR EACH parameter IN request.form
qsdata = qsdata & parameter & "=" & request.form(parameter) & "&"
NEXT

If Right(qsData,1) = "&" Then
qsData = Left(qsData,len(qsData) -1)
End If
response.redirect "http://www.domain.com/newpage.asp?" & qsData

That would do the trick without encryption. If you want to encrypt, make a function to do your encryption and use EncryptFunction(request.form(parameter)) while looping.

Again, the session variable is the best way to go - just giving you another option if it's not available :)

MozMan

3:43 pm on Aug 26, 2004 (gmt 0)

10+ Year Member



Thanx guys, I appreciate the feedback. I was afraid it wouldn't be a simple as I had hoped. :)

What you suggested is actually what I ended up having to do. Works like a charm; it's just that I'm lazy and didn't want to write any more code than I had to! :)

wackal

4:27 pm on Aug 26, 2004 (gmt 0)

10+ Year Member



you might want to look into server.transfer

this will keep the form collection available on the new page

digitalv

4:33 pm on Aug 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it's just that I'm lazy and didn't want to write any more code than I had to

We programmers refer to that as "efficient code" not laziness :)

MozMan

5:06 pm on Aug 26, 2004 (gmt 0)

10+ Year Member



Yes... efficient code. very troo! :)

I tried server.transfer, the probblem with it is that you can't specify a complete url, only a relative path, so I couldn't transfer to https...