AD LDS를 사용하기 때문에 인증 모드 "Windows"가 도움이 될 것이라고 생각하지 않습니다. 로그인보기 (여기/계정/로그온)를 만들고 인증 모드 "양식"을 사용해야한다고 생각합니다.
는 System.DirectoryServices.AccountManagement를 사용하여 수행 할 수 있습니다 Web.config의 사용자를 인증
<authentication mode="Forms">
<forms name=".ADAuthCookie" loginUrl="~/Account/Logon" timeout="30" slidingExpiration="false" protection="All"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
에 followwing를 입력합니다. 컨트롤러 코드는 다음과 같아야합니다.
public ActionResult Logon(LogonModel model)
{
if (model.Username != null && model.Password != null)
{
string container = "CN=...,DC=....,DC=...."; //Your container in LDS
string ldapserver = "server:port"; //LDS server
PrincipalContext context = new PrincipalContext(
ContextType.ApplicationDirectory,
ldapserver,
container,
ContextOptions.SimpleBind);
bool authenticate = context.ValidateCredentials(string.Format("CN={0},{1}", model.Username, container), model.Password, ContextOptions.SimpleBind);
if (authenticate)
{
FormsAuthentication.RedirectFromLoginPage(model.Username, false);
}
else
{
System.Threading.Thread.Sleep(5000);
this.ModelState.AddModelError("Password", "Wrong username or password");
}
}
return View("Logon", new LogonModel { Username = model.Username });
}
이 경우에만 인증을 해결하며 권한 부여는 해결되지 않습니다.
멤버쉽 공급자를 사용할 수도 있지만 쉬운 해결책을 찾고 있다면이 트릭을 수행해야합니다.
사용자 지정 공급자를 쓸 필요는 없습니다. 다른 LDAP 도구를 사용하여 연결할 수 있습니까? –