Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using this method of faking an SPContext: http://solutionizing.net/2009/02/16/faking-spcontext/

public static SPContext FakeSPContext(SPWeb contextWeb)
  // Ensure HttpContext.Current
  if (HttpContext.Current == null)
    HttpRequest request = new HttpRequest("", web.Url, "");
    HttpContext.Current = new HttpContext(request,
      new HttpResponse(TextWriter.Null));

  // SPContext is based on SPControl.GetContextWeb(), which looks here
  if(HttpContext.Current.Items["HttpHandlerSPWeb"] == null)
    HttpContext.Current.Items["HttpHandlerSPWeb"] = web;

  return SPContext.Current;

Now, if I need this context to have identity of a specific SharePoint user. Any ideas how would I do that?

share|improve this question
Not sure what for do you want to have such fake context, but to impersonate as another user, you can use SPSite constructor overload, as described here: sharepoint.stackexchange.com/questions/28241/… –  Andrey Markeev Feb 6 '12 at 18:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.