Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.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
.net 使用Azure移动服务的SignalR获取用户名_.net_Signalr_Azure Mobile Services_Azure Active Directory - Fatal编程技术网

.net 使用Azure移动服务的SignalR获取用户名

.net 使用Azure移动服务的SignalR获取用户名,.net,signalr,azure-mobile-services,azure-active-directory,.net,Signalr,Azure Mobile Services,Azure Active Directory,我一直在从事.NET后端移动服务。对于身份验证,我使用Azure Active Directory。对于前端,使用Windows RT应用程序。随着signar最近引入.net移动服务,我想我应该看看它。我很快就遇到了以前许多人都遇到过的将SignalR ConnectionId与经过身份验证的用户相关联的问题 我在网上找到的每个资源都说要使用Context.User.Identity.Name。我已将Authorize属性添加到我的中心,以仅允许经过身份验证的连接。我遇到的问题是,即使我的用户

我一直在从事.NET后端移动服务。对于身份验证,我使用Azure Active Directory。对于前端,使用Windows RT应用程序。随着signar最近引入.net移动服务,我想我应该看看它。我很快就遇到了以前许多人都遇到过的将SignalR ConnectionId与经过身份验证的用户相关联的问题

我在网上找到的每个资源都说要使用Context.User.Identity.Name。我已将Authorize属性添加到我的中心,以仅允许经过身份验证的连接。我遇到的问题是,即使我的用户登录到Azure Active Directory,Context.user.Identity.Name始终为空

Context.User.Identity.IsAuthenticated为true,Context.User.Identity.AuthenticationType为联合


有什么我没有正确理解的吗?

关于第一个问题,我不太清楚,但一般来说,您可以自定义客户端的方式。用户通过自己实现IUserIdProvider并将您的实现注入信号器来返回给定用户的连接。这样,您可以检查您的请求并从中提取更多信息。如果您在请求中找到了所需的部分,可能是某个标题,或者您可以从那里使用它来关联相关的连接


选中移动服务基础结构设置上下文。用户将成为包含用户信息的ServiceUser。例如,Context.User.Id提供用户Id,Context.User.ProviderIdentity提供来自各种登录提供程序(包括访问令牌)的信息

希望这有帮助


亨里克

这里是一个问题示例。在我的应用程序中与SignalR无关,但我使用Azure AD。当连接Hotmail帐户时,我将Context.User.Identity.Name设置为null。当用户与azure ad位于同一域中时,则不适用

在这两种情况下,这是相同的: Context.User.Identity.IsAuthenticated为true,Context.User.Identity.AuthenticationType为联合