How do you handle a session and multiple tabs in ASP.NET?

I wrote an application in ASP.net that allows a user to add records to a database. The page is configured so that when the user adds the record, the identification number of the newly added record is set in the session, the Response.Redirects page to the "Thank you for sending" page, then redirects back to the original page to allow further changes. Users can also use the back button on this screen to return to the original page for adding entries, which allows them to edit the data.

However, I found that storing the identifier in the session is not a very good solution, as the user may try to create two documents in different tabs or windows. I also tried setting the identifier in the literal control, but this causes a problem when the user uses the back button, the literal control is not set to the identifier, and new entries are added instead of being edited.

Is there any solution for this?

+4
source share
7 answers

Stupid question, why can the user use the "Back" button to edit the data just received in the message?

If previously published editing data is a common scenario, why not just redirect to the page when the data is received, allowing you to edit it. Then, if you click the "Back" button, they will return to the original "clean" insert / add a new data page.

This will give the following streams Add β†’ [message] β†’ Edit β†’ ..... Add β†’ [Post] β†’ Edit β†’ [Back button] β†’ Add β†’ [Post] β†’ Edit β†’ [Post] β†’ Edit ....

+1
source

I would recommend storing your ID in a QueryString. After adding the entry, redirect to the "thankyou" page, which, I believe, contains a link to the editing form that you will generate with the identifier in querystring. When this link is executed, the page edit page pulls the identifier from the query string to load the correct entry for editing.

Your form of adding and editing can even be the same page, when the identifier is specified in the request, your form knows that you need to change this record, otherwise your form will add a new record.

+5
source

Have you tried adding an identifier to the query string? You can then read it and add it to the session as needed (for example, when the user clicks the back button).

It looks like a lot of problems allowing you to edit the object on the page displayed when using the back button. Would it be too much to give them an edit button?

+1
source

The controls retain their state in the ViewState. If you decide to use SessionState instead of ViewState to store information, then the controls will retain their state in session state and will not work with multiple tabs.

I have not yet found a way around this problem when using SessionState. Our solution was to use a regular ViewState.

0
source

I tried to save the id in querystring (which is mostly great for editing), but the problem is that the information is stored in the session when the back button is used. If the user does the following:

  • The user creates a record (first record), the identifier is transmitted in the query string and temporarily stored in the session.
  • The user creates another record (second record), the identifier is transmitted in the query string temporarily stored in the session.
  • The user uses the "Back" button in the first entry to go to a page that has no queue.

This is probably a contrived scenario, but it can happen. The only solution I have is to block the use of the back button to return to the add page using window.history.forward () in JavaScript. But this is a terrible decision.

0
source

My question for you is why do you keep something in session? If you can not store anything in the session, I think you will be the best.

0
source

After thinking about this, does a similar worthy solution to the problem described above sound like?

  • The first time you add an entry, save the timestamp when a hidden area has been added to the access page.
  • This timestamp passes through the session when the user clicks the Save button. Along with the identifier.
  • If the user simultaneously opens another tab and saves it, then the timestamp of the new page passes through the session.
  • If the user tries to access the page for adding the first record (using the "Back" button), the system looks at the session and sees if there is a timestamp and whether it matches that in the hidden field for this page.
  • If this does not match, the user receives an invitation and is told to edit the entry correctly.

Does this sound reasonable or too complicated?

0
source

All Articles