【发布时间】:2021-08-04 13:07:07
【问题描述】:
使用以下代码,我没有错误,但所有登录都因登录错误而失败。
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using MVCFBAWithAD.Models;
using System.Security;
using System.Configuration;
using Galactic.ActiveDirectory;
using System.DirectoryServices.Protocols;
using System.Security.Principal;
我正在使用包Galactic.ActiveDirectory。
这是控制器的一部分:
[Authorize]
public class AccountController : Controller
{
// GET: /Account/Login
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
string serverName = ConfigurationManager.AppSettings["ADServer"];
if (ModelState.IsValid)
{
SecureString securePwd = null;
if (model.Password != null)
{
securePwd = new SecureString();
foreach (char chr in model.Password.ToCharArray())
{
securePwd.AppendChar(chr);
}
}
try
{
// Check user credentials
ActiveDirectory adVerifyUser = new ActiveDirectory(serverName, model.UserName, securePwd);
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
return RedirectToLocal(returnUrl);
}
catch
{
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
return View(model);
}
}
catch块释放,变量有如下值。
ActiveDirectory adVerifyUser = new ActiveDirectory(serverName, model.UserName, securePwd)
我尝试了几种组合,但都不起作用。
带域名:
serverName = \\\\SCD1000
model.UserName = DOMAINNAME\\Dirk
securePWD = {System.Security.SecureString}
没有域名和反斜杠
serverName = SCD1000
model.UserName = Dirk
securePWD = {System.Security.SecureString}
..等等。
您可以在字符串变量中看到双反斜杠\\。我认为这属于转义序列,这不是错误的原因吗?
谁能帮助我或知道问题出在哪里?
【问题讨论】:
-
Not 捕捉和吃掉你的异常将是查看实际错误消息的第一步。
标签: c# asp.net asp.net-mvc-5