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?

有帮助吗?

解决方案

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.

其他提示

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.

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;
}

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.

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

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top