Security Context of Background Thread

  • Thread starter Thread starter Matt
  • Start date Start date
M

Matt

I've written a class that allows me to add documents to a SharePoint
Document Library from another web application. The web app runs under
a domain account that has permissions to SharePoint. However, when I
try to do this from a background thread it fails with Access Denied.
I've tested the WindowsIdentity from the background thread and it is
the same. Are background threads not running in the same security
context under ASP.NET 2.0? Following is my code, Button1 works,
Button2 does not.

protected void Button1_Click(object sender, EventArgs e) {
SPDocLibDataAccess da = new SPDocLibDataAccess("http://
staff.mcrcsip.org", "");
da.AddDocument("D:\\Temp\\LicensedVehiclesDetailReport.pdf", "Shared
Documents");
this.lblMessage.Text = "Done!";
}
protected void Button2_Click(object sender, EventArgs e) {
ThreadStart ts = new ThreadStart(this.UploadFile);
Thread t = new Thread(ts);
t.Start();
this.lblMessage.Text = "Started thread.";
}

private void UploadFile() {
SPDocLibDataAccess da = new SPDocLibDataAccess("http://
staff.mcrcsip.org", "");
da.AddDocument("D:\\Temp\\LicensedVehiclesDetailReport.pdf", "Shared
Documents");
}
 
I had impersonation enable without realizing it. The foreground
thread was executing under the logged in user's account which had
permissions on the SharePoint site. The background thread was
executing under the identity of the Application Pool, which didn't
have permissions on the SharePoint site.
 
Back
Top