How to store authenticated user information in WCF?

I have a WCF service where I use customUserNamePasswordValidatorType (specified in the \ serviceBehaviors \ serviceCredentials \ userNameAuthentication behavior section of the web.config file).

My custom UserNamePasswordValidator works this way:

public bool Authenticate(string userName, string password)
{
     If ( IsUserValid(username, password) )
    {
        UserInfo currentUser = CreateUserInfo(username);
       //
       // Here I'd like to store the currentUser object somewhere so that
       // it can be used during the service method execution
       //
       return true;
    }
    return false;

}

While making a service call, I need to access authenticated user information. For example, I would like to be able to implement:

public class MyService : IService
{
     public string Service1()
    { 
       //
       // Here I'd like to retrieve the currentUser object and use it
       //
       return "Hello" + currentUser.Name;
    }
}

My question is how and where to store information during the authentication process so that it can be obtained during the call process? This storage should continue as long as the "session" is valid.

, ( ) / . , SecuritytContext, safeSessions .

, ASP.NET HttpContext.Current.Session, , , .

+3
1

, . , .

, . ASP.NET - . ( , ..) , .

, WCF - ​​ "" , .

+2

Source: https://habr.com/ru/post/1725447/


All Articles