设置模拟,我创建了一个非常简单的项目,它试图计算两个目录中文件的数量。 User1
不允许访问Directory2
和User2
不允许访问Directory1
。由于模拟,我只能得到一个号码,这取决于正在呼叫我的应用程序的用户。这两个用户都设置为管理员。为了第一次理解,使用ASP.NET
因此,我在Visual Studio 2015(在Windows 8.1上运行)中创建了一个新的MVC项目,并选择使用Windows身份验证。一旦应用程序启动并运行(在ISS Express中),我在我的机器上切换到User1
(没有Active Directory)并在Internet Explorer中调用网站(是,在设置中启用了“集成Windows身份验证”)。通过此设置,HttpContext.User.Identity
中的用户User1
和WindowsIdentity.GetCurrent()
是我的开发用户,是我在Visual Studio中使用的用户。
我也尝试手动模拟:“要么未提供所需的模拟级别,或提供的模拟级别无效”
WindowsIdentity winId = (WindowsIdentity)User.Identity;
WindowsImpersonationContext ctx = null;
try
{
ctx = winId.Impersonate();
// GetNumbers() tries to get the number of files for both directories
numbers = GetNumbers();
}
catch (Exception e)
{
}
finally
{
if (ctx != null)
{
ctx.Undo();
}
}
不幸的是,我得到的异常有些人声称这个人解决了他们的问题:https://kc.mcafee.com/corporate/index?page=content&id=KB56194不适合我。我已将User1
和我自己的用户添加到列表中并重新启动计算机。不用找了。
唯一给我带来一点希望的是使用单独登录的模仿,如https://msdn.microsoft.com/en-us/library/ms998351.aspx#paght000023_impersonatingusinglogonuser所述。缺点非常明显:我必须拥有用户密码,如果用户已经登录为我做了。
虽然这是不被我大的变化一个新的项目,只是为了完整性检查一些信息...
我Web.config
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
我的项目设置
- “匿名身份验证”是
false
- “Windows authenticat离子”是
true
- ‘管理pipline模式’
Integrated
什么改变,使这个简单的项目按预期方式工作有什么建议?
最好的问候, 卡斯滕