2009-06-29

Elevated Privliges, Kerberos, NTLM, Pool Account Identity, Impersonation, etc

Here are some code snippets that I frequently use to run code with extra privliges, access resources using WebRequest, etc.:

// Accessing resource files using Pool Account credentials, for example,
// to avoid 401 Unatohorized Access messages in production
using (HostingEnvironment.Impersonate())
{
WebRequest req = WebRequest.Create("url to my xsl file");
StreamReader reader = new StreamReader(req.GetResponse().GetResponseStream(),
System.Text.Encoding.UTF8);


...
}


// To run code with eleavted privligies:

No comments: