3

I have a registration form and want to transfer the user to the success page, telling him that an email was sent to his email. I need to transfer his email from the register page to the success page.

I found about Server.Transfer, but I can't find out how to send parameters. I don't want to use query string as I don't like revealing information in the URL.

What is the proper way (if possible) to do this?

Simon Dugré
  • 17,980
  • 11
  • 57
  • 73
TheGateKeeper
  • 4,420
  • 19
  • 66
  • 101

6 Answers6

6
Server.Transfer("destination.aspx", true)

You might see that the above code contains the name of the page to which the control is transferred and a Boolean value ‘True’ to indicate to preserve the current form state in the destination page.

Chris Gessler
  • 22,727
  • 7
  • 57
  • 83
3

Set a property in your login page and store in it, the email.

Once this is done, do a Server.Transfer("~/SuccessPage.aspx", true);

On the other page, where you redirected, you should check something like that :

if(this.PreviousPage != null) {
    ((LoginPageType)this.PreviousPage).MyEmailProperty;
}
Simon Dugré
  • 17,980
  • 11
  • 57
  • 73
2

When you using server transfer you just move execution to different server handler , user will no see the new url or the parameters so it safe to make this transfer.

MichaelT
  • 7,574
  • 8
  • 34
  • 47
2

I would rather recommend that you do it differently.

When the user clicks the register button, you verify it all and then send the email from the still current page (so you need not transfer data to another page at all). If all went well, you just redirect:

Response.Redirect("/order/success.aspx");

If something was wrong (validation errors, sending email caused an exception) you are still on the right page for a retry. I would not use Server.Transfer at all in most cases.

1

You'll have to persist the value somewhere. The obvious options are in the Session object, or in a database.

mgnoonan
  • 7,060
  • 5
  • 24
  • 27
  • Session state is a very bad place to store it. It would persist in the memory when I only want to use it once. – TheGateKeeper Apr 26 '12 at 17:05
  • 1
    Agreed, but my statement that you had to persist it *somewhere* was correct. Ultimately that ended up being the query string, which is better than Session, but your question was leaning towards not using it. – mgnoonan Apr 26 '12 at 17:24
  • Yes I know, I marked up your question. I was unaware that server.transfer kept the previous URL, so query string is viable now. – TheGateKeeper Apr 26 '12 at 20:04
1

For this kind of use case. You can use Context.Items to save the data with a key and read the value using the same key in the child page you are doing the Server.Transfer. Context.Items are sort of per request scoped cache for you.
Context.Items['DataKey'] = Data;
Server.Transfer("~/AnyRouteRelativePath", true);

swemkg
  • 117
  • 1
  • 7
  • 1
    Thank you, Thank you, Thank you -- this works perfectly when using it for custom error handling in the global.asax Application_Error as well... I was trying to keep default requestvalidation for XSS but show a custom error screen with the error - most things I tried kept re-erroring due to the event model for request validation in 4.5. This way I added it to the cache and retrieve in the Error page - perfect. – CooPzZ May 07 '20 at 08:42