ASP.NET 成员身份 - 哪个用户经过身份验证,哪个用户被模拟?
我在尝试了解 ActiveDirectory 和 ASP.NET 成员资格如何工作时有点困惑...我创建了一个新的 MVC 项目并删除了 AccountController / Views。 我更改了 Web.Config,以便它使用 ActiveDirectory 并根据当前的 Windows 登录自动对用户进行身份验证:
Web.Config
<authentication mode="Windows">
<forms
name=".ADAuthCookie"
timeout="10" />
</authentication>
<membership defaultProvider="MyADMembershipProvider">
<providers>
<clear/>
<add
name="MyADMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADConnectionString"
connectionUsername="MYDOMAIN\myuser"
connectionPassword="xxx"
/>
</providers>
</membership>
这很好用,因为我可以执行以下操作来获取用户用户名,例如this:
User.Idenity.Name() 'Gives MYDOMAIN\myuser
看看下面的内容,实际上让我很困惑:
Threading.Thread.CurrentPrincipal.Identity.Name() 'Gives MYDOMAIN\myuser
1。 线程标识不应该是 IUSR_WORKSTATION 或 ASPNET_WP 用户名吗?
2. 身份验证和模拟有什么区别?
i'm a little confused while trying to find out how ActiveDirectory and ASP.NET Membership work... I've created a new MVC project and removed the AccountController / Views. I've changed the Web.Config so that it uses ActiveDirectory and automatically authenticates users based on their current Windows login:
Web.Config
<authentication mode="Windows">
<forms
name=".ADAuthCookie"
timeout="10" />
</authentication>
<membership defaultProvider="MyADMembershipProvider">
<providers>
<clear/>
<add
name="MyADMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADConnectionString"
connectionUsername="MYDOMAIN\myuser"
connectionPassword="xxx"
/>
</providers>
</membership>
This works nicely, as I can do the following to get the users username like this:
User.Idenity.Name() 'Gives MYDOMAIN\myuser
Looking at the following, actually makes me confused:
Threading.Thread.CurrentPrincipal.Identity.Name() 'Gives MYDOMAIN\myuser
1. Shouldn't the thread identity be IUSR_WORKSTATION or ASPNET_WP username?
2. What's the difference between Authentication and Impersonation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
myuser 是该应用程序上经过身份验证的用户,这就是为什么您的 CurrentPrincipal 为您提供 MYDOMAIN/myuser。 应用程序在使用数据库等资源时会模拟 IUSR_WORKSTATION,这是一个完全不同的问题。
如果您转到工具栏上的“项目”,然后选择“ASP.NET 配置”,它将打开一个网站,您可以在其中访问这些设置并创建用户、角色等。
myuser is the Authenticated user on that application, that's why your CurrentPrincipal is giving you MYDOMAIN/myuser. The application impersonates IUSR_WORKSTATION when it uses resources like the database, and is a completely different issue.
If you go to Project on your toolbar, and select ASP.NET Configuration, it will open a website that lets you access these settings and create users, roles etc.