title: Best practices for Run with elevated privelege
body: <p>Among the two approaches which one is preferred with run with elevated privileges?</p>
  
  <p>First Approach:</p>
  
  <pre><code>SPSecurity.RunWithElevatedPrivileges(delegate()
                  {
                      using (SPSite curSite = new SPSite(SPContext.Current.Site.ID))
                      {
                          using (SPWeb web = curSite.OpenWeb(SPContext.Current.Web.ID))
                          {
                              try
                              {
                                  web.AllowUnsafeUpdates = true;
                                  \\ do your stuff
                              }
                              catch (Exception e)
                              {
  
                              }
                              finally
                              {
                                  web.AllowUnsafeUpdates = false;
                                  web.Dispose();
                              }
                          }
                      }
                  });
  </code></pre>
  
  <p>Second Approach:</p>
  
  <pre><code>SPSite oSite = SPContext.Current.Site;
  SPWeb oWeb = SPContext.Current.Web;
  SPSecurity.RunWithElevatedPrivileges(delegate()
                  {
                      using (SPSite curSite = new SPSite(oSite.ID))
                      {
                          using (SPWeb web = curSite.OpenWeb(oWeb.ID))
                          {
                              try
                              {
                                  web.AllowUnsafeUpdates = true;
                                  \\ do your stuff
                              }
                              catch (Exception e)
                              {
  
                              }
                              finally
                              {
                                  web.AllowUnsafeUpdates = false;
                                  web.Dispose();
                                  oWeb.Dispose();
                                  oSite.Dispose();
                              }
                          }
                      }
                  });
  </code></pre>
  
  <p>Are any of them suspected to throw "The web being updated was changed by an external process" exception ?</p>