views:

74

answers:

2

My web app is set to use Windows Authentication and Impersonation is set to true.

<authentication mode="Windows"/>
    <identity impersonate="true"/>

When I run it on my local machine (IIS6), I access Active directory with my current login.

WindowsIdentity curIdentity = WindowsIdentity.GetCurrent();
WindowsPrincipal myPrincipal = new WindowsPrincipal(curIdentity);

However when I access my site remotely Impersonation does not seem to be working; I display the groups that the user belongs to - and get a very short list!

What else do I need?

A: 

I'm pretty sure you need to be specifying a user:

<identity impersonate="true" userName="contoso\Jane" password="pass"/>

Otherwise it will use the ASP.Net user, which will have limited privileges.

See here for more information (including how to store the username/password encrypted).

BarrettJ
+1  A: 

Impersonation does not pass credentials more than 1 hop between machines. So your creds go from your machine to IIS but no further, accessing active directory is a 2nd hop. When everything runs on the same machine (as in your local case), it will work fine.

http://msdn.microsoft.com/en-us/library/aa292118%28VS.71%29.aspx

Roatin Marth
...unless you are using Kerberos.
JohnFx
true it is more complex than this, you can start getting into account delegation and such to work around the limitation
Roatin Marth
OK, so just to confirm something... there is no way to get the (correct) username without using kerberos?
Grayson Mitchell
Right, worked out some important definitions:1\ If you are using integrated security you are using Kerberos (this has been a confusing point, when people are refering to Kerberos they are usually talking about connecting to sql server)2\ turn off anonymous access in IIS!!! - this solved my problem
Grayson Mitchell