首页 > 解决方案 > 如何在 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 赞赏。

标签: c#linuxwindowsasp.net-core.net-core

解决方案


推荐阅读