如何获取Windows用户名时身份冒充= QUOT;真"在asp.net? [英] How to get Windows user name when identity impersonate="true" in asp.net?
问题描述
我创建一个内联网asp.net大家在公司应该有机会获得MVC应用程序。我需要运行模拟数据库访问等的网站,但我想知道每个用户是谁。
I'm creating an intranet asp.net mvc application that everyone in the company should have access to. I need to run the website impersonated for database access etc., but I want to know who each user is.
当我在看 Page.User.Identity.Name
这是一片空白。是否有可能获得用户的Windows帐户,即使网站运行模拟的名字吗?
When I look at Page.User.Identity.Name
it's blank. Is it possible to get the user's windows account name even though the site is running impersonated?
编辑:
这里有一个小的详细信息。我在IIS 6中的站点匿名访问运行启用。该网站是在有访问数据库(因为所有的员工没有访问数据库)的系统帐户下运行。
Here's a little more info. I have a site in IIS 6 running with anonymous access enabled. The site is running under a system account that has access to the database (because all of the employees do not have access to the database).
我的web.config中有<身份验证模式=窗口/>
和<身份冒充=真/>
My web.config has <authentication mode="Windows" />
and <identity impersonate="true"/>
我的目标是,用户不必登录 - 这一事实,他们登录到我们的网络(而事实上,该网站是不是在一个外部IP)是不够的认证。我只是想知道用户是为了跟踪他们做出改变,谁等。
My goal is that the users won't have to log in - that fact that they are logged into our network (and the fact that the site is not on an external IP) is enough authentication. I would just like to know who the user is in order to track changes they make, etc.
推荐答案
通过&LT;身份验证模式=窗口/&gt;在您的应用程序和匿名访问中启用了
IIS,你会看到以下结果:
With <authentication mode="Windows"/>
in your application and Anonymous access enabled in IIS, you will see the following results:
System.Environment.UserName: Computer Name
Page.User.Identity.Name: Blank
System.Security.Principal.WindowsIdentity.GetCurrent().Name: Computer Name
使用&LT;身份验证模式=窗口/&GT;
在你的应用程序,并在IIS匿名访问禁止,只集成Windows身份验证,你会看到以下结果:
With <authentication mode="Windows"/>
in your application, and ‘Anonymous access’ disabled and only ‘Integrated Windows Authentication’ in IIS, you will see the following results:
System.Environment.UserName: ASPNET (user account used to run ASP.NET service)
Page.User.Identity.Name: Domain\ Windows Account Name
System.Security.Principal.WindowsIdentity.GetCurrent().Name: Computer Name\ASPNET
使用&LT;身份验证模式=窗口/&GT;
和&LT;身份冒充=真/&GT;
在你的应用程序,并在IIS匿名访问禁止,只集成Windows身份验证,你会看到以下结果:
With <authentication mode="Windows"/>
and <identity impersonate ="true"/>
in your application, and ‘Anonymous access’ disabled and only ‘Integrated Windows Authentication’ in IIS, you will see the following results:
System.Environment.UserName: Windows Account Name
Page.User.Identity.Name: Domain\ Windows Account Name
System.Security.Principal.WindowsIdentity.GetCurrent().Name: Domain\ Windows Account Name
这篇关于如何获取Windows用户名时身份冒充= QUOT;真&QUOT;在asp.net?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!