【发布时间】:2020-05-23 17:42:23
【问题描述】:
我正在使用表单授权针对活动目录登录我的 Web 应用程序,我想做的是在用户登录时模拟该用户。但是我遇到了一些问题,当我通过 IIS 或 web.config 启用模拟时,我收到 500 错误,这是我的 web.config 的那部分:
<customErrors mode="Off"/>
<authentication mode="Forms">
<forms name=".ADAuthCookie" loginUrl="~/Login/Index" timeout="45" slidingExpiration="false" protection="All" path="/" />
</authentication>
<identity impersonate="true" />
<membership defaultProvider="ADMembershipProvider">
<providers>
<clear />
<add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName" />
</providers>
</membership>
如果我在身份元素中设置我的凭据,它可以在不调整我的 IIS 的情况下工作:
<identity impersonate="true" userName="domain\username" password="password" />
这是我在 IIS 中的授权,这也是它当前设置的:
如果我禁用匿名并启用模拟,我会收到 500 错误。
我做错了什么以及如何让表单身份验证与模拟一起使用。
这是我的登录控制器:
[HttpPost]
public ActionResult Index(Login model, string returnUrl)
{
if (!ModelState.IsValid)
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
if (Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
return RedirectToAction("Index", "Home");
}
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
更新
我通过<validation validateIntegratedModeConfiguration="false" /> 传递了 500 错误,但除非我设置凭据,否则模拟仍然无法工作。我可以设置登录人的凭据吗?
更新
当我运行此代码时,我可以看到它填充了正确的用户名,并且 impersonate 设置为 true,我做错了什么?
System.Security.Principal.WindowsIdentity.GetCurrent()
【问题讨论】:
-
HTTP 500 错误的内容是什么?这听起来很重要且相关。
-
500 - 内部服务器错误。您要查找的资源有问题,无法显示。
-
如果我转到 Web 应用程序中的任何页面,就会发生这种情况
-
您需要启用详细的 HTTP 500 错误消息。您是否配置了错误日志记录?
-
这是answered 多年前。
标签: c# asp.net asp.net-mvc iis impersonation