【问题标题】:signalR-1.0.0-rc2 User Identity not workingsignalR-1.0.0-rc2 用户身份不起作用
【发布时间】:2013-02-14 22:52:03
【问题描述】:

我尝试使用 signalR 1.0.0 RC2,因为我注意到自 0.5.3 以来很多东西都发生了变化,其中一件不起作用的是“Context.User.Identity.Name",这给了我空值,我不确定,这仍然是访问 Windows 用户身份的正确方法吗?

  [HubName("chatroom")]
 public class ChatRoomHub : Hub
 {
    public void Join()
    {
      User newUser = new User();

      newUser.ClientID = Context.ConnectionId;
      newUser.Login = Context.User.Identity.Name.Split('\\')[1];
      newUser.Content = " joined discussion";
      newUser.DateTime = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss");

      this.Clients.Join(newUser);
    }       
  } 

string name = Context.User.Identity.Name; // name is blank here

在 1.0.0 RC2 中,Context.User.Identity.Name 为空

【问题讨论】:

  • 你能说得更具体一点吗?你是在自托管还是 asp.net 上?你在做什么?
  • 在 asp.net 中,这种方法在 0.5.3 中有效
  • 它应该在 rc2 上的 ASP.NET 中仍然可以正常工作。
  • public override Task OnConnected() { string name = Context.User.Identity.Name; // name is blank here. return Clients.All.joined(Context.ConnectionId, DateTime.Now.ToString()); }
  • 提交错误并附加重现项目。

标签: jquery asp.net signalr signalr-hub signalr.client


【解决方案1】:

在我的项目中,这解决了问题:

(文件:Web.config)

<system.web> 
    <authorization>
        <deny users="?" />
    </authorization>
</system.web>     

希望这会有所帮助。

【讨论】:

  • 发现这不是 SignalR 的问题。当使用 IIS 或使用 Visual Studio 开发服务器选项托管在服务器上时,根本没有问题。但是在 VS 中使用本地 IIS Web 服务器选项时,用户标识为空白。感谢您的回复。
猜你喜欢
  • 2015-07-13
  • 2018-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多