Transferring data between asp.net pages

I am interested in the opinion of what is the best way to pass a lot of values ​​between multi-page pages. I was thinking about storing values ​​in a database using context.Items [] or Session []. I am not sure if this is the best method. I probably pass about 40 variables. This will be during the validation process, so they must be preserved through the users life cycle. The user does not change the values ​​after entering them for the first time. Values ​​will be like Billing Address, First and Last name, etc.

+4
source share
4 answers

The session is probably the most effective. However, if the timeout session is lost or lost for any other reason, any records are lost. Therefore, if saving is more important, you might want to save it in db.

+4
source

Maybe Forward Page Option?

Another option would be the Server.Transfer method Server.Transfer along with the Context.Items or Form property.

In this case, any published form variables and query string parameters are available for the second / third / etc. pages.

But the URL in the browser will not be changed until you go to another page.

One thing you need to know about is that if the first page wrote something in the Answer Buffer, and you do not clear it, then any output from the second page will be added to the first output. This often causes strange behavior when it seems that the page returns two different pages. In addition, since the transfer takes place on the server, you cannot transfer the request to an external site.

More information can be found here .

+3
source

Passing values ​​through session variables doesn't work too well. You may also have chances when the user clicks the back button or updates clicks and session variables collect garbage. This is the way to go for any cached items. One way is when the user goes to the second page, you take all the variables and put them in a hidden field somewhere, separated by a pair of Key: Value.

If values ​​can be placed publicly, why not just put them in a URL?

If you cannot do this by adding them to the database and providing them with the Guid identifier for the username, this will be the last alternative for me, since you need to read and write to the database for each request.

+1
source

The answer depends entirely on what the user expects the next time he returns to your site. Does he expect you to remember the contact information that he has already entered? If so, then you will have to use long-term storage in the database, cookies, etc. Is your user entering other information just for this visit (for example, a customer service application) and next time enters other information they visit? If so, then you might want to use a Session object.

+1
source

Source: https://habr.com/ru/post/1306960/


All Articles