Reputation: 1452
I was following this tutorial at http://www.codeproject.com/Articles/380900/WCF-Authentication-and-Authorization-in-Enterprise
Now I have it logging in and everything, no problems infact it works just like it should. I've even added some cryptography to it using MD5 hashing. But I'm not sure how to get the users information. So when they call the Utility service, how would I query the database for that specific user?
[PrincipalPermission(SecurityAction.Demand, Role = "Read")]
public Data.UserProfiles ViewProfile()
{
using (var context = new DatabaseEntities())
{
var user = context.UserProfiles.SingleOrDefault(u => u.UserName == ???)
return user;
}
}
Upvotes: 0
Views: 133
Reputation: 1890
If you are using the WCF in web application you can store the user details in cookie as the CodeProject article does or you can follow WCF Authentication as here: msdn.microsoft.com/en-us/library/ff405740.aspx
Use below code to get user: var currentUser = new WindowsPrincipal((WindowsIdentity) System.Threading.Thread.CurrentPrincipal.Identity);
Upvotes: 1