C# ServiceStack服务OnUnsubscribe\OnSubscribe\OnConnect用户名错误
在我的服务堆栈中,我有以下AuthRepository初始化:C# ServiceStack服务OnUnsubscribe\OnSubscribe\OnConnect用户名错误,c#,.net,servicestack,httpserver,C#,.net,servicestack,Httpserver,在我的服务堆栈中,我有以下AuthRepository初始化: var userRep = new InMemoryAuthRepository(); container.Register<IUserAuthRepository>(userRep); string hash; string salt; var pwd = "ValidPassword"; new SaltedHash().GetHashAndSaltString(pwd, out hash, out salt);
var userRep = new InMemoryAuthRepository();
container.Register<IUserAuthRepository>(userRep);
string hash;
string salt;
var pwd = "ValidPassword";
new SaltedHash().GetHashAndSaltString(pwd, out hash, out salt);
userRep.CreateUserAuth(new UserAuth
{
Id = 1,
DisplayName = "CustomDisplayName",
Email = "test@gmail.com",
UserName = "CustomUserName",
FirstName = "FirstName",
LastName = "LastName",
PasswordHash = hash,
Salt = salt,
}, pwd);
var userRep=newinMemoryAuthRepository();
容器注册(userRep);
字符串散列;
弦盐;
var pwd=“ValidPassword”;
new SaltedHash().GetHashAndSaltString(pwd,out hash,out salt);
userRep.CreateUserAuth(新UserAuth
{
Id=1,
DisplayName=“CustomDisplayName”,
电子邮件=”test@gmail.com",
UserName=“CustomUserName”,
FirstName=“FirstName”,
LastName=“LastName”,
PasswordHash=hash,
盐=盐,
},pwd);
在同一个服务中,我有一些事件处理程序:
private void OnUnsubscribe(IEventSubscription obj)
{
Console.WriteLine(obj.DisplayName + " has unsubbed\n");
}
private void OnSubscribe(IEventSubscription obj)
{
Console.WriteLine(obj.DisplayName + " has subbed\n");
}
private void OnConnect(IEventSubscription obj, Dictionary<string, string> dict)
{
Console.WriteLine(obj.DisplayName + " has connected\n");
}
private void OnUnsubscribe(IEventSubscribtion obj)
{
Console.WriteLine(obj.DisplayName+“已取消填充\n”);
}
认购的私人无效(IEventSubscription obj)
{
Console.WriteLine(obj.DisplayName+“有子床\n”);
}
连接上的私有无效(IEventSubscription obj,字典dict)
{
Console.WriteLine(obj.DisplayName+“已连接\n”);
}
问题是我的
obj.DisplayName
是CustomUserName而不是CustomDisplayName(并且obj.UserName
也是CustomUserName)。这就是它的工作原理吗?如果是-如何更改DisplayName?目前,我使用默认的CredentialAuthProvider
为经过身份验证的用户使用会话。用户名
如果存在,因为它是唯一的,如果没有定义,则返回到用户显示名称
您可以使用ServerEventsFeature.OnCreated()
自定义挂钩更改返回到服务器事件客户端的自定义元数据,例如,您可以更改返回的displayName
:
Plugins.Add(new ServerEventsFeature
{
OnCreated = (sub, req) => {
sub.Meta["displayName"] = req.GetSession().DisplayName;
}
});