身份模拟=“true"时如何获取Windows用户名在asp.net 中? [英] How to get Windows user name when identity impersonate="true" in asp.net?

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

问题描述

我正在创建一个 Intranet 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.

推荐答案

在您的应用程序中使用 <authentication mode="Windows"/> 并在 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 

在您的应用程序中使用 <authentication mode="Windows"/> 并且在 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 NameASPNET

在您的应用程序中使用 <authentication mode="Windows"/><identity impersonate ="true"/> 和匿名访问"在 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

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

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