를 사용하고있어
는 얻을 수 있도록 Active Directory의
체크 아웃으로이 링크 인터페이스가 사용자의 시작 :
http://www.schiffhauer.com/mvc-5-and-active-directory-authentication/
계정 컨트롤러 :
여기
링크에서 소스 코드입니다
using System.Web.Mvc;
using System.Web.Security;
using MvcApplication.Models;
public class AccountController : Controller
{
public ActionResult Login()
{
return this.View();
}
[HttpPost]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (!this.ModelState.IsValid)
{
return this.View(model);
}
if (Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
if (this.Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return this.Redirect(returnUrl);
}
return this.RedirectToAction("Index", "Home");
}
this.ModelState.AddModelError(string.Empty, "The user name or password provided is incorrect.");
return this.View(model);
}
public ActionResult LogOff()
{
FormsAuthentication.SignOut();
return this.RedirectToAction("Index", "Home");
}
}
계정보기 모델 :
using System.ComponentModel.DataAnnotations;
public class LoginModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
마지막으로 web.config 반면 업데이트 :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<authentication mode="Forms">
<forms name=".ADAuthCookie" loginUrl="~/Account/Login" timeout="45" slidingExpiration="false" protection="All" />
</authentication>
<membership defaultProvider="ADMembershipProvider">
<providers>
<clear />
<add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName" />
</providers>
</membership>
</system.web>
<connectionStrings>
<add name="ADConnectionString" connectionString="LDAP://primary.mydomain.local:389/DC=MyDomain,DC=Local" />
</connectionStrings>
</configuration>
이 확실히, 당신이 시작하는 데 도움이 생각보다 컨텍스트에 대한 링크를 체크 아웃해야합니다. 이 도움이 더 필요하면 알려주세요