C# Galactic.ActiveDirectory不';我不能在ASP MVC上工作

C# Galactic.ActiveDirectory不';我不能在ASP MVC上工作,c#,asp.net,asp.net-mvc-5,C#,Asp.net,Asp.net Mvc 5,使用下面的代码,我没有错误,但是所有登录都会失败,因为登录不正确 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.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}
。。等等

您可以在字符串变量中看到双反斜杠
\\
。我认为这属于转义序列,这不是错误的原因


有谁能帮我或者知道问题出在哪里吗?

不是服务器名,而是域名

ActiveDirectory构造函数(字符串、字符串、SecureString、字符串)

不捕获并吃掉异常是查看实际错误消息的第一步。另请参阅
domainName

Type: System.String
   The DNS style domain name of the Active Directory to connect to.
userName
   Type: System.String
   The username of the account in AD to use when making the connection.
password
   Type: System.Security.SecureString
   The password of the account.
siteName (Optional)