Mailing List


Active Directory Products
Object Compare
Permission Compare

IPhone Products
Calls To Calendar
SMS To Gmail
Voicemail To Gmail

How Long For Me
My Music To Me


NerdyHearn - Blog

<< Back To All Blogs

Impersonating a user in ASP.NET

Wednesday, July 1st, 2009

It has been a while since I've had to do ASP.NET Impersonation, but I was presented with a situation today in which it was required. I figured I would give a few quick tips for doing so, how to impersonate, and how you can debug some of the issues during the process.

In ASP.NET Impersonation, it is done at the entire application level. You simply have to add an entry under the system.web entry in web.config to impersonate a user for the running process.

An example would be like the following:
<identity impersonate="true" userName="DOMAINUser" password="password" />

Note: Because the entire process runs as this user, you may get an error stating that the user does not have permissions to access C:\Windows\Microsoft.NET\Framework\VX.X.X\Temporary ASP.NET Files. To fix this issue, simply go to the stated path, right click to get to properties, and add the user to the directory permissions with write permissions.

To confirm that the application is running under the context of the user you have provided, you can use the following code block to determine if it is indeed running under the user:
string username = System.Security.Principal.WindowsIdentity.GetCurrent().Name

Pretty basic for the most part, but just wanted to share because it always takes me a minute to remember the process.

Impersonatin' Tom Out.



Related Blogs

Updating an LDAP Property in C#
Calculating ISO 8601 Date formats in C#, C++, and Java
Good Ol Cross-Threaded Socket Action
Using MOSS and WSS SharePoint Workflow to Resize Images in an Image Library
Retrieving the SID of a user or group account using the Win32 SDK and C#


Currently no comments.

Add A Comment



Email Address: (not public, used to send notifications on further comments)


Enter the text above, except for the 1st and last character:

NerdyHearn - Latest tech news relating to C#, ASP.NET, SharePoint, PHP, general development, and more. DocuTerminal - Online Filing Cabinet solution. Scan, search and archive your paper documents. SaveMySerials - Protect yourself from theft, fire, natural disasters and more by recording your serial numbers My Music To Me - Stream your subsonic music collection to your Sonos wireless system TypeCount - Count how often you type across different computers! ServrTrackr - Monitor your SSL certificates, website uptime, and DNS configurations