我已經讀了很多指南/文章,但還沒有找到一個還沒有,它正是我想要的......那就是通過形式來實現在ASP.NET Web API的Active Directory認證。如何通過Forms在ASP.NET Web API中實現Active Directory身份驗證?
事情是這樣的指南:
Cool MVC 5 guide to implement authentication with Active Directory
這是非常好的,但它是MVC,即,它採用了控制器不是ApiController
可有人請給我提示/提示/關於如何開始的文章?特別是關於連接到活動目錄的部分。我一直堅持這一點。
UPDATE:
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);
}
}
我想嘗試像這樣的認證,你的想法?