Worrying about concurrency issues - should I only allow 1 user at the time?
<p>I’m working on an administration tool for a project that does a small amount of reading and writing to different files and some database queries and updates. Now I believe it’s improbable that we would ever have an issue with this since we’re not that many people using this project. But if I can, I want to minimize or eliminate the risk of it ever happening while not disturbing the normal users. I'm using Windows Authentication and Roles. </p>

<p>One of my ideas is to create a lock and only allowing 1 user to administer at the time. By using the Session.SessionID and saving it in the Application state as an exclusive lock. E g if a user would want to administer he would first go to a landingpage and there where would be this check (oh, this isn't atomic I take it?):</p>

<pre><code>if (Application["lockedBy"] == null)
{
    Application["lockedBy"] = Session.SessionID;
    Application["lockedName"] = User.Identity.Name;
    Response.Redirect("Admin.aspx");
}
</code></pre>

<p>And the admin page there would be a button to release the lock and redirect to another page. Or if the user forgets using the Session_End() in the global.asax file and having an autorefresh. But how would this stop someone from pressing the browsers backbutton and bypassing this?</p>

<p>Or should I try to make sure the configuration files haven’t been changed before writing to them? But how would I save the state for this page. Should I like save the files modification time in Session state and if they diff just abort the save action? </p>

<p>So the question is: how should I protect my application from concurrency issues while not disturbing the normal users?</p>
