如何在C#中找到系统的用户名? [英] How can be find the user name of system in C#?

查看:72
本文介绍了如何在C#中找到系统的用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让系统的用户名在本地主机中正常工作,但在服务器中使用此cade时它会返回空白。



我是什么尝试过:



i希望得到系统的用户名在本地主机上正常工作但是当在服务器中使用此cade时它返回空白。

i want to get the user name of system its works properly in local host but when use this cade in server it return blank.

What I have tried:

i want to get the user name of system its works properly in local host but when use this cade in server it return blank.

推荐答案

您需要为IIS中的网站启用Windows身份验证。
You will require Windows Authentication enabled for the website in IIS.


问题是您将始终获取用户名服务器,而不是客户端 - 看起来它适用于您的开发计算机,因为它在同一台计算机上运行,​​而IIS本地主机在您的用户ID下运行。 C#代码总是在服务器上执行,永远不会在客户端上执行 - 它基本上只能运行Javascript。

当你发布到生产时,代码检索运行IIS的服务器的用户名,这很可能是因为它不是作为真实用户运行而空白。

您无法在C#中检索客户端的登录用户名,并且您无法在javascript中的所有浏览器中获取该用户名。
The problem is that you will always fetch the username of the Server, not the Client - it looks like it works on your development machine because it runs on the same computer and IIS local host executes under your user ID. C# code always executes on the Server, never on the client - which can basically only run Javascript.
When you release to production, the code retrieves the username for the server running IIS, which is likely to be blank as it's not running as a "real" user.
You cannot retrieve the login username for a client in C#, and you can't get it in all browsers in javascript.


这篇关于如何在C#中找到系统的用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆