I already tried link from stackoverflow
I have a silverlight client and wcf service. The application has 3 authentication modes
- Active Directory
- Windows Pass Through
- Proprietary - I don't have a problem with this one obviously. (I really don't know what is the difference between active directory and Window Pass Through. I just use the same code for both, except for windows pass through I get the current user and for AD the app prompts for username password)
.
private string GetCurrentUser()
{
try
{
string result = WindowsIdentity.GetCurrent().Name;
WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
result = wp.Identity.Name;
if (result.Contains(@"\"))
{
int position = result.LastIndexOf(@"\") + 1;
result = result.Substring(position);
}
return result;
}
catch (Exception ex)
{
return "";
}
}
Both WindowsIdentity and WindowsPrincipal returns 'DefaultAppPool' or whatever the AppPool the current thread runs. Even Environment.UserName returns the same.
When I turn on <identity impersonate ="true"/>
in web.config the silverlight client fails to connect to wcf. It gets a 'Not Found' error. So, I need to keep <identity impersonate ="false"/>
All I need is the current logged on user, I didn't know that it's this difficult.