通过ASP.Net页面获取域用户名(当前登陆的用户)

1 string domainAndName = Page.User.Identity.Name;
2 string[] infoes = domainAndName.Split(new char[1] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
3 string userDomainName = "";
4 string userName = "";
5 if (infoes.Length > 1)
6 {
7 userDomainName = infoes[0];
8 userName = infoes[1];
9 }

需要注意的地方(可能出现问题的地方已经解决方案):

1.将IIS Authentication设置为:Windows Authentication,并且只有这一项

2.在ASP.Net的Web.Config中添加:<identity impersonate="true"/> <authentication mode="Windows"/>

3.发布到IIS后,将Application Pool选择为Classic的

4.将IIS的 ISAPI and CGI Restrictions设置为Allowed

以上是查阅很多资料之后总结的心得。

posted @ 2011-03-14 17:40  HelloWorld.Michael  阅读(8967)  评论(9编辑  收藏  举报