在线用户新增IP显示
This commit is contained in:
parent
956b496fa0
commit
58f5de7037
@ -42,12 +42,13 @@ namespace ZR.Admin.WebApi.Hubs
|
|||||||
public override Task OnConnectedAsync()
|
public override Task OnConnectedAsync()
|
||||||
{
|
{
|
||||||
var name = Context.User.Identity.Name;
|
var name = Context.User.Identity.Name;
|
||||||
|
var ip = HttpContextExtension.GetClientUserIp(App.HttpContext);
|
||||||
LoginUser loginUser = JwtUtil.GetLoginUser(App.HttpContext);
|
LoginUser loginUser = JwtUtil.GetLoginUser(App.HttpContext);
|
||||||
var user = clientUsers.Any(u => u.ConnnectionId == Context.ConnectionId);
|
var user = clientUsers.Any(u => u.ConnnectionId == Context.ConnectionId);
|
||||||
//判断用户是否存在,否则添加集合
|
//判断用户是否存在,否则添加集合
|
||||||
if (!user && Context.User.Identity.IsAuthenticated)
|
if (!user && Context.User.Identity.IsAuthenticated)
|
||||||
{
|
{
|
||||||
clientUsers.Add(new OnlineUsers(Context.ConnectionId, name, loginUser?.UserId));
|
clientUsers.Add(new OnlineUsers(Context.ConnectionId, name, loginUser?.UserId, ip));
|
||||||
Console.WriteLine($"{DateTime.Now}:{name},{Context.ConnectionId}连接服务端success,当前已连接{clientUsers.Count}个");
|
Console.WriteLine($"{DateTime.Now}:{name},{Context.ConnectionId}连接服务端success,当前已连接{clientUsers.Count}个");
|
||||||
//Clients.All.SendAsync("welcome", $"欢迎您:{name},当前时间:{DateTime.Now}");
|
//Clients.All.SendAsync("welcome", $"欢迎您:{name},当前时间:{DateTime.Now}");
|
||||||
Clients.All.SendAsync(HubsConstant.MoreNotice, SendNotice());
|
Clients.All.SendAsync(HubsConstant.MoreNotice, SendNotice());
|
||||||
|
|||||||
@ -16,13 +16,15 @@ namespace ZR.Model
|
|||||||
public long? Userid { get; set; }
|
public long? Userid { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public DateTime LoginTime { get; set; }
|
public DateTime LoginTime { get; set; }
|
||||||
|
public string UserIP { get; set; }
|
||||||
|
|
||||||
public OnlineUsers(string clientid, string name, long? userid)
|
public OnlineUsers(string clientid, string name, long? userid, string? userip)
|
||||||
{
|
{
|
||||||
ConnnectionId = clientid;
|
ConnnectionId = clientid;
|
||||||
Name = name;
|
Name = name;
|
||||||
LoginTime = DateTime.Now;
|
LoginTime = DateTime.Now;
|
||||||
Userid = userid;
|
Userid = userid;
|
||||||
|
UserIP = userip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user