kamagra how much to take

Use the SystemAccount Property When Building SPUserToken Objects

I saw a developer doing this with some funky impersonation today, so I thought I would throw out some sample code. Consider the below shell code, demonstrating the SPSite.SystemAccount property use, subsequently using it to expose the SystemAccount.Token property to pass into the SPSite constructor.

  1. SPWeb primaryWeb = SPContext.Current.Web;
  2. using (var primarySite = new SPSite(primaryWeb.Site.ID))
  3. {
  4. SPUserToken userToken = primarySite.SystemAccount.UserToken;
  5. using (var secondarySite = new SPSite(primarySite.ID,userToken))
  6. {
  7. using (SPWeb secondaryWeb =secondarySite.OpenWeb(primaryWeb.ID))
  8. {
  9.  
  10. try
  11. {
  12.  
  13. }
  14. catch (Exception)
  15. {
  16. }
  17.  
  18. }
  19. }
  20. }
Share

One Comment

  1. .Net Follower says:

    Hello!
    In my blog I described how to receive UserToken of SystemAccount even if code is running under user with limited rights. It’s here
    http://dotnetfollower.com/wordpress/2011/03/sharepoint-how-to-get-systemaccount-token/

Trackbacks/Pingbacks

  1. Links (10/18/2009) « Steve Pietrek – Everything SharePoint - [...] Use the SystemAccount Property When Building SPUserToken Objects [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>