views:

252

answers:

1

I'm writing an ASP.net application and I'm working with the WindowsIdentity.GetCurrent() function. I want to know how (or if it's possible) to change what identity the ASP.net application runs as.

I eventually want to run it as an account associated with the end-user. I understand I can do this with Windows Authentication in IIS, but Windows Authentication will not work with my particular application. If I can programmatically log the user in with a AD username and password, that will be fine.

How can I set the WindowsIdentity the ASP.net application runs as without using Windows Authentication in IIS?

Update: This question has been sitting idle for a long time. I think that perhaps the framework does not allow me to do what I'm describing here. Does anyone know for sure that this is prohibited or considered bad practice?

+3  A: 

You need to use Impersonation

Or if you'd like to implement Impersonation using strictly Code, check this example:

How to implement impersonation in an ASP.NET application

Justin Niessner
Impersonation works to a point to perform an action as a certain identity, however it is very cumbersome to have to impersonate with every action that must be performed as a certain user.With Windows Authentication, you can set <identity impersonate="true"/> in web.config and it will be impersonated automatically. I desire to have this same functionality even though I am not using impersonation.
Rice Flour Cookies
You're not going to be able to accomplish what you're asking without using some form of impersonation.
Justin Niessner
So, to clarify then, are you saying that if I'm not using Windows Authentication in IIS, I cannot use the <identity impersonate="true"/> in the web.config to automatically impersonate a programmatically logged in user?
Rice Flour Cookies
No, that's not what I'm saying. I thought you were saying that Impersonation wasn't acceptable for you. Check this table to see what is possible with the different settings: http://msdn.microsoft.com/en-us/library/aa302377.aspx
Justin Niessner
Actually, I've already seen the document you link to. In the table, the author indicates that without some Windows Authentication, only the ASP.net process or anonymous user will be returned.That's why I'm asking, is it possible to set the user returned by WindowsIdentity.GetCurrent() programmatically.
Rice Flour Cookies
You could attempt to use something like the code found here: http://www.15seconds.com/Issue/040511.htm to map whatever your authentication scheme is to Windows Users...and then log those users on programatically.
Justin Niessner