title: How to get and set a persistent variable server side in a web application
body: <p>I am trying to save a simple int on the server side then any user can log in and update it. I thought this would be a simple task and began trying to use the settings designer however i couldn't change the scope from "application" to "user" as application settings are read only.</p>
  
  <p>I know i could save and change the variable in an XML file but i thought there must be a more simple way.</p>
  
  <p>I have tried to use user profiles, however it isn't working any ideas? (I have also used Context.Profile.)</p>
  
  <pre><code>&lt;profile&gt;
    &lt;providers&gt;
      &lt;clear/&gt;
      &lt;add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/&gt;
    &lt;/providers&gt;
    &lt;properties&gt;
      &lt;add name="FilmNumber" type="int" allowAnonymous="true" defaultValue="2"/&gt;
    &lt;/properties&gt;
  &lt;/profile&gt;
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>//********Get poster Number*******
  int LastPosterNumber=0;
  LastPosterNumber = (int)HttpContext.Current.Profile.GetPropertyValue("FilmNumber");
  
  string strFileName;
  strFileName = FileField.PostedFile.FileName;
  string c = (LastPosterNumber + 1).ToString();
  string dirPath = System.Web.HttpContext.Current.Server.MapPath("~") + "/Images/FilmPosters/" + c + ".jpg";
  FileField.PostedFile.SaveAs(dirPath);
  
  //******Save new poster number*******
  HttpContext.Current.Profile.SetPropertyValue("FilmNumber", int.Parse(c));
  HttpContext.Current.Profile.Save();
  </code></pre>