title: Overriding SaveChanges and setting ModifiedDate, but how do I set ModifiedBy?
body: <p>I have an ASP.NET MVC3 web application with UI, Business (entities), and Data (DbContext) layers.  I am using Entity Framework 4.1 Code First. Right now, I am overriding the <code>DbContext.SaveChanges()</code> in the Data layer so that I can set the <code>ModifiedDate</code> for all changes made to any entity objects that implement my <code>IAuditable</code> interface. I have a static <code>DateProvider</code> class and method (GetCurrentDate) that returns <code>DateTime.Now</code> (unless I'm running a test, in which case, it returns whatever I told it to). </p>
  
  <p>I would like to automatically set the <code>ModifiedBy</code> property to the current user as well.  What is the best way to go about doing this? Is there something that is built in the framework that will allow me to access this information or do I need to set something up kind of like the <code>DateProvider</code> class? This is an Active Directory environment and we use <code>WindowsAuthentication</code> in IIS.</p>
  
  <p>Here is my SaveChanges code:</p>
  
  <pre><code>public override int SaveChanges()
  {
      var changeSet = ChangeTracker.Entries&lt;IAuditable&gt;();
  
      if (changeSet != null)
      {
          foreach (var entry in changeSet.Where(c =&gt; c.State != EntityState.Unchanged))
          {
              entry.Entity.ModifiedDate = DateProvider.GetCurrentDate();
          }
      }
      return base.SaveChanges();
  }
  </code></pre>