问题描述
我一直在阅读很多指南/文章,但还没找到一个完全符合我想要的...那就是通过表单在ASP.NET Web API中实现Active Directory身份验证。
本指南中的内容:
哪个非常好,但它是对于MVC,即它使用Controller而不是ApiController
有人可以给我提示/提示/文章如何开始吗?特别是关于连接到活动目录的部分。我已经坚持了一段时间。
更新:
I've been reading a lot of guides/articles but haven't found one yet that does exactly what I want... that is to implement Active Directory Authentication in an ASP.NET Web API through forms.
Something like on this guide:
Cool MVC 5 guide to implement authentication with Active Directory
Which is very good but it's for MVC, i.e., it uses a Controller not an ApiController
Can someone please give me hints/tips/articles on how to start? Especially about the part that connects to the active directory. I've been stuck on this for a while.
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);
}
}
我正在考虑尝试这样的事情进行身份验证,你的想法?
I was thinking of trying something like this for the authentication, your thoughts?
推荐答案
这篇关于如何通过表单在ASP.NET Web API中实现Active Directory身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!