MrD*_*pan 45 asp.net-mvc impersonation
我正在创建一个内部网asp.net mvc应用程序,公司中的每个人都应该可以访问它.我需要运行模拟数据库访问的网站等,但我想知道每个用户是谁.
当我看着Page.User.Identity.Name它的空白时.即使网站正在模拟运行,是否可以获取用户的Windows帐户名称?
编辑: 这里有更多信息.我在IIS 6中有一个运行匿名访问的站点.该站点在可以访问数据库的系统帐户下运行(因为所有员工都无权访问数据库).
我的web.config有<authentication mode="Windows" />和<identity impersonate="true"/>
我的目标是用户不必登录 - 他们登录我们网络的事实(以及该网站不在外部IP上的事实)是足够的身份验证.我想知道用户是谁以跟踪他们所做的更改等.
小智 121
随着<authentication mode="Windows"/>您的应用程序,并在IIS中启用匿名访问,您将看到以下结果:
System.Environment.UserName: Computer Name
Page.User.Identity.Name: Blank
System.Security.Principal.WindowsIdentity.GetCurrent().Name: Computer Name 
随着<authentication mode="Windows"/>在你的应用程序,而"匿名访问"禁用的,只有"集成Windows身份验证"在IIS中,您将看到以下结果:
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
随着<authentication mode="Windows"/>并<identity impersonate ="true"/>在你的应用程序,和"匿名访问"禁用的,只有"集成Windows身份验证"在IIS中,您将看到以下结果:
System.Environment.UserName: Windows Account Name 
Page.User.Identity.Name: Domain\ Windows Account Name 
System.Security.Principal.WindowsIdentity.GetCurrent().Name: Domain\ Windows Account Name
尝试这个
System.Security.Principal.WindowsIdentity.GetCurrent().Name
它应该返回带有用户登录名的字符串