如何在asp.net中获取当前的Windows用户? [英] How to get current windows user in asp.net?

查看:365
本文介绍了如何在asp.net中获取当前的Windows用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了很多代码,它在我的本地服务器上成功运行。但我尝试将远程服务器放到另一个字符串,如IIS APPPOOL,servername....我改为IIS管理器中的一些设置,但我失败了。
我如何获得远程服务器中的用户名

I tried lots of code it Works successfuly in my local server. But I tried it to put remote server they get another strings such as IIS APPPOOL, "servername" .... I change to some settings in IIS manager but I failed. How can i get username in remote server

我尝试了一些代码,如:

I tried some codes like:

System.Security.Principal.WindowsPrincipal= System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;

  string strName = p.Identity.Name;

string strName = HttpContext.Current.User.Identity.Name.ToString();

string Name = Environment.GetEnvironmentVariable("USERNAME");

string Name = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();
    string usernamex = currentIdentity.Name.ToString();

HttpContext.Current.User.Identity.Name.ToString();


推荐答案

假设您使用的是IIS 7.5,请执行以下操作。其他版本将类似。以上所有获取用户名的方式都应该有效。

Assuming you are using IIS 7.5 do the following. Other versions will be similar. All the above ways of getting the username should then work.

1) Double click on Authentication (This can be done at server level and your web site level so check both!)
2) Right click on Anonymous authentication and disable it and likewise enable Windows authentication
3) Click Basic settings. Check which application pool your website is using. Ensure it is using pass-through authentication for an "Application User" by clicking "Connect As" i.e. A user using a browser will be the person requesting authentication.
4) Click "Application Pools". Click the Application pool from (3). Click "Advanced Settings". Check the Identity is set to ApplicationPoolIdentity


这篇关于如何在asp.net中获取当前的Windows用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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