【发布时间】:2015-03-25 09:43:21
【问题描述】:
我已经阅读了很多指南/文章,但还没有找到完全符合我要求的...即通过表单在 ASP.NET Web API 中实现 Active Directory 身份验证。
类似于本指南的内容:
Cool MVC 5 guide to implement authentication with Active Directory
这非常好,但它适用于 MVC,即它使用控制器而不是 ApiController
有人可以给我关于如何开始的提示/提示/文章吗?特别是关于连接到活动目录的部分。我已经被困了一段时间了。
更新:
public bool IsAuthenticatedUser(string srvr, string usr, string password)
{
bool authenticated = false;
try {
DirectoryEntry entry = new DirectoryEntry(srvr, usr, password);
object nativeObject = entry.NativeObject;
Object obj = entry.NativeObject;
authenticated = true;
}
catch {
throw new HttpResponseException(HttpStatusCode.Unauthorized);
}
return authenticated;
}
// POST: api/Login
public void Post([FromBody]string username, [FromBody]string password)
{
if (IsAuthenticatedUser("LDAP string", username, password))
{
Redirect("Index");
}
else
{
throw new HttpResponseException(HttpStatusCode.Unauthorized);
}
}
我正在考虑尝试这样的身份验证,你的想法?
【问题讨论】:
标签: c# asp.net asp.net-web-api active-directory directoryservices