0

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;
        }
    }
4

1 回答 1

1

如果您在 Web 应用程序中使用 WCF,您可以像 CodeProject 文章那样将用户详细信息存储在 cookie 中,或者您可以按照此处的 WCF 身份验证:msdn.microsoft.com/en-us/library/ff405740.aspx

使用以下代码获取用户: var currentUser = new WindowsPrincipal((WindowsIdentity) System.Threading.Thread.CurrentPrincipal.Identity);

于 2013-07-20T07:46:45.963 回答