Setting impersonation values programmatically

I

itmanager

We have an ASP.NET application (v1.1) that requires some impersonation in
order to access network shares.

We have the following setting in the web.config file:

<identity impersonate="true" />

This allows the application to access network shares if the web site is
using Basic or Integrated Windows authentication; however, when using
Anonymous Authentication, it fails unless we also specify a user name and
password in clear text within the file; ie:

<identity impersonate="true"

userName="domain\user"
password="password" />

Due to security concerns, we do not want to specify this information in
clear text.

Is there a way to impersonate a particular user programmatically rather than
entering the value in the web.config file? Can this be done without resorting
to impersonation within a service?

Thanks for any assistance.
 
J

Joe Kaplan

The "canonical" sample is shown in the .NET Framework MSDN reference on the
WindowsImpersonationContext class documentation. You can basically copy and
paste that. There are some subtle flaws in this implementation, and Shawn
Farkas has written more about how to do this "the right way" on his blog.
Google will find it.

Joe K.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top