简体   繁体   English

Nancy Self主机获取所有已连接客户端IP的列表

[英]Nancy Self host get list of all connected clients` IPs

I have a console application in C# with nancy self host, it currently works well, we can access session data with the Request.Session object. 我在C#中有一个带有nancy self host的控制台应用程序,它目前运行良好,我们可以使用Request.Session对象访问会话数据。 My question is how can we get a list of all the connected clients in a module or Program class? 我的问题是如何获取模块或程序类中所有已连接客户端的列表? like a list of ips and session ids so that we can access any connected client's session object. 例如ip和会话ID列表,以便我们可以访问任何连接的客户端的会话对象。 Your help would be appreciated! 您的帮助将不胜感激!

There is nothing out of the box that you can give you that however you can try something like : 开箱即用,您可以尝试以下操作:

 public static ConcurrentDictionary<string, Nancy.Session.ISession> Clients = new ConcurrentDictionary<string, Nancy.Session.ISession>();

 protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context){
   base.RequestStartup(container, pipelines, context);
   clients.TryAdd(context.Request.UserHostAddress, context.Request.Session);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM