我刚刚在我的开发人员PC上安装了AD LDS,所有工作都可以找到,我甚至通过ADSI Edit创建了用户"abc“。
我的目标是使用我的测试AD LDS实例来测试我的ASP.NET MVC3Web应用程序。
如何让app根据实例对用户进行身份验证?我是否必须编写自定义成员资格提供程序?(是否覆盖默认AD成员提供程序中的某些内容?)
谢谢你的帮助!
发布于 2012-11-20 16:32:04
您不必进行任何身份验证,因为它由iis处理。您所要做的就是将身份验证模式更改为windows。
<system.web>
<authentication mode="Windows" />
</system.web>请记住,要么在安装AD的之后安装iis ,要么手动注册它。
发布于 2012-11-20 18:12:39
因为您使用的是AD LDS,所以我认为身份验证模式"Windows“不会有太大帮助。我认为您需要创建一个登录视图(此处为/Account/Logon),并使用身份验证模式“表单”。
在web.config中输入跟随机翼
<authentication mode="Forms">
<forms name=".ADAuthCookie" loginUrl="~/Account/Logon" timeout="30" slidingExpiration="false" protection="All"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization> 可以使用System.DirectoryServices.AccountManagement完成对用户的身份验证。控制器代码应该如下所示:
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 });
}请注意,这只解决了身份验证问题,而不能解决授权问题。
您也可以使用会员提供者,但如果您正在寻找一个简单的解决方案,我认为这应该可以做到这一点。
https://stackoverflow.com/questions/9283283
复制相似问题