0

Any idea what's the purpose of UserManager.UpdateSecurityStamp? I call it every time a user logs in to my ASP.Net Core 3.0 application and occasionally gets Optimistic concurrency failure, object has been modified. Any advice and insight is appreciated. What's it's use case and the root cause of the Optimistic concurrency exception?

Kok How Teh
  • 3,298
  • 6
  • 47
  • 85
  • 1
    [docs](https://learn.microsoft.com/en-us/previous-versions/dn497517(v%3Dvs.108)) maybe? It basically invalidates previous sessions for all other users who were logged in before and its use cases are named in the docs to: _used for SignOutEverywhere functionality_ (i.e. when a user changes a password, log out all other sessions the user was logged in before) – Tseng Oct 17 '19 at 13:34
  • What's the use case and root cause of the optimistic concurrency exception? – Kok How Teh Oct 17 '19 at 13:38
  • Too prevent two update operations to change override each others changes. i.e. two requests happening on the same milisecond reading state A from database, and both doing different changes. One (the first) will succeed, the second will fail because the concurrency token was changed. In this cause you should handle the concurrency (just retry and accept that data from the first updated operation may be lost/overwritten) or solve the concurrency by applying your updates to the new version of the dataset (basically loading the entity and reapplying your changes)... – Tseng Oct 17 '19 at 13:42
  • or if you figure out its incompatible inform the user and ask whether its okay to override it or not. Its always developers task to solve the concurrency issue based on the business requirement. – Tseng Oct 17 '19 at 13:43
  • Any reference how to properly handle this exception in the `catch` block? – Kok How Teh Oct 17 '19 at 13:52

0 Answers0