Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ServiceStack服务OnUnsubscribe\OnSubscribe\OnConnect用户名错误_C#_.net_<img Src="//i.stack.imgur.com/WM7S8.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">servicestack_Httpserver - Fatal编程技术网 servicestack,httpserver,C#,.net,servicestack,Httpserver" /> servicestack,httpserver,C#,.net,servicestack,Httpserver" />

C# ServiceStack服务OnUnsubscribe\OnSubscribe\OnConnect用户名错误

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);

在我的服务堆栈中,我有以下AuthRepository初始化:

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