c# - 如何在 asp.net 核心 Web 应用程序中使用 System.Net.Dns.GetHostEntry(ip).HostName 获取用户名?
问题描述
我的应用程序中没有登录页面,我试图在 Windows 和 Linux 服务器上获取 Web 应用程序的当前用户名。
这是我尝试过的
var ip = HttpContext.Connection.RemoteIpAddress;
string[] computer_name = System.Net.Dns.GetHostEntry(ip).HostName.Split(new Char[] { '.' });
var getuserid = computer_name[0].ToString();
正如您在这张图片中看到的, 拆分后computer_name
返回[0] computername, [1] myurl ,[2] com
。但我无法在返回的数组中获取我的用户名。
我也试过this.User.FindFirstValue(ClaimTypes.NameIdentifier);
,但它返回空值。
我在我的controller
.
任何 hep 赞赏。
解决方案
推荐阅读
- pyspark - pyspark - 并行化文件处理的问题
- html - 带有短垂直线的 CSS 样式导航栏
- php - 如何通过 Ajax jQuery 发送多个输入值
- python - 是否可以使 __init__ 文件动态描述父包?
- javascript - 使用jquery的相同嵌套数组数据的总和
- flutter - 如何在自己弹出时导航到命名路线?
- python - 请帮助计算使用 Python 或 Pandas 的设备数量?
- html - npm 包正在创建一个带有已编译 css 的 dist 文件夹,该 css 覆盖了主 css 文件夹
- phpmyadmin - 我正在尝试设置 phpmyadmin 并收到警告。我试图解决这些问题,但对我没有用。谁能帮我?
- reactjs - 通过单击按钮显示来自 firebase 的单个数据信息