开发者

Stateful session with nhibernate and asp.net

开发者 https://www.devze.com 2023-03-12 23:21 出处:网络
Let\'s say I have a client who is filling up a data from a website. the underlying persistence used is Nhibernate.

Let's say I have a client who is filling up a data from a website. the underlying persistence used is Nhibernate.

Now the series of events goes like this

  1. user fills up the form开发者_Python百科 .
  2. he submits the form .
  3. the nhibernate sessionfactory is created and via customer object its is saved to database .
  4. the database commits the session object using a native generator for nhibernate
  5. but a mishap happens before the response from the server reaches the client . the connection to the client goes off .
  6. the client gets to see a page not found error or request time out error . and has a dilemma that he isnt registered yet .
  7. so he again presses the refresh button . and the same set of data (although that is committed to database ) has been send to server for database commit.
  8. the server sees the data and again registers the same customer with different id .
  9. so the problem goes like . now the same customer entry has been duplicated two times cause the connection has got cut off .

Now can someone tell me how to proceed into this scenario. So that even if the customer submits he just recognizes only one entry and submits it, even if the response has got cut off and he presses the refresh button?


Thoughts:

1) You don't want to create the NHibernate SessionFactory on every request. This should be created once and then used by all future requests. It's a heavy-weight operation. Only the Sessions need to be created each request.

2) Manage the transaction in a high level method - to reduce the likelihood of something going wrong AFTER you've committed the transaction, but BEFORE the client has a response.

3) Guard against the "Refresh" method resubmitting, by having the submit function return a different page which presents the information. This page should not submit anything.

4) Guard against a resubmit server side by validating the submission against previously submitted credentials. Inform the client if they've previously registered and provide them with a means to access the saved details (Password recovery for example.)

so for example if your users are keyed by email address then in the page load event perform the following steps:

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号