【问题标题】:Get SessionID and UserHostAddress in .Net Core在 .Net Core 中获取 SessionID 和 UserHostAddress
【发布时间】:2022-02-14 16:54:17
【问题描述】:

在普通的asp.net中,我们可以通过给出this的值:

UserSessionID = System.Web.HttpContext.Current.Session.SessionID;
IPAddress = System.Web.HttpContext.Current.Request.UserHostAddress;

我们如何在 .Net Core 中获得相同的结果。有人可以帮忙吗?

【问题讨论】:

标签: c# asp.net-core-mvc


【解决方案1】:

假设您的会话设置如下:

HttpContext.Session.SetString("mysession", "mySessionValue");

然后就可以获取Session id了:

UserSessionID = HttpContext.Session.Id;

以及用户主机地址:

IPAddress = HttpContext.Connection.RemoteIpAddress;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-10
    • 2011-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多