【发布时间】:2016-11-01 20:14:46
【问题描述】:
Context.User.Identity.Name 一直为空,目前我正在使用 WebForms:
HttpCookie cookie = new HttpCookie("jamal");
cookie.Value = "bilal";
HttpContext.Current.Response.Cookies.Add(cookie);
这里我要用户名:
public override Task OnConnected()
{
AddUser(Context.User.Identity.Name, this.Context.ConnectionId);
}
private static void AddUser(String username, String connectionId)
{
ISet<String> connections;
if (users.TryGetValue(username, out connections) == false)
{
connections = users[username] = new HashSet<String>();
}
connections.Add(connectionId);
}
【问题讨论】:
-
你在哪里打电话给
Context.User.Identity.Name?另外,用户是否经过身份验证?
标签: c# webforms httpcontext