Asp.net MVC 集成AD域认证

1.首先WebApi 应用下Web.config要配置域认证服务器节点,如下

<!--LDAP地址 用于项目AD系统账号密码验证-->

<!--0:关闭域认证;1:开启域认证-->
<add key="EnableADCheck" value="0"/>
<add key="LDAPAPI" value="域认证服务器的api地址"/>  

2.Api控制器Controller

public class LDAPController : ApiController { /// <summary> /// 用于AD验证 /// </summary> /// <param></param> /// <param></param> [AllowAnonymous] [HttpPost] public HttpResponseMessage Check(HttpRequestMessage req) { try { SimpleLog.WriteLog(LogFile.Trace, "" + " start"+ req.Content.ReadAsStringAsync().Result); dynamic data = DynamicJson.Parse(req.Content.ReadAsStringAsync().Result); var decrPwd = ""; var account = data.Account; var pwd = data.Pwd; try {//1.先对密码进行解密 decrPwd = AESEnCryptUtils.Decrypt(pwd); } catch (Exception ex) { SimpleLog.WriteLog(LogFile.Error, "解密失败:" + ex.Message); return JsonBuilder.Build("error" + "-解密失败" + ex.Message); } var result = ADHelper.CheckExist(account, decrPwd).ToString(); SimpleLog.WriteLog(LogFile.Error, "End:" + result); return JsonBuilder.Build(result); } catch (Exception ex) { SimpleLog.WriteLog(LogFile.Error,ex.Message+"-"+ ex.StackTrace); return JsonBuilder.Build(ex.Message); } } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwpfgg.html