简体   繁体   中英

How do I access username on the server side using Windows authentication on a WCF service?

I have Silverlight application with a WCF service using Windows Authentication. My users get authenticated correctly. And I can access their username and roles on client side. But how do I do the same thing on server side? I've tried this

ServiceSecurityContext.Current.WindowsIdentity

and

IIdentity caller = ServiceSecurityContext.Current.PrimaryIdentity;

It is what I found as an answer on a similar question here on stackoverflow but it doesn't compile. I get a 'ServiceSecurityContext does not contain definition for Current' exception.

So how do I get the user on server side?

public static string GetUserIdentity()
{
   return OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name;
}

OperationContext is in the System.ServiceModel namespace.

try

HttpContext.Current.User;

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM