学习01 C# MVC LDAP 登录认证

网友投稿 897 2022-09-09

学习01 C# MVC LDAP 登录认证

首先想说明使用C# 来开发Web 版的CMDB是个人的原始需求, 并没有领导或者公司内部有专门的项目支持我做这个事情, 但是考虑到自己的兴趣和职业发展, 自己向自己提了一个需求 ---搭建一个Web CMDB

之前也有了解过市场上有很多开源的CMDB 和付费的CMDB 产品, 但是总之一句话, 系统是别人的, 不能把公司实际的业务需求100%都涵盖了, 或者说不想使用多余(个人认为)的功能

所以有了总的目标之后一系列的小目标或者分支需求, 接二连三的自己给自己提了一大堆, 一边提需求一边自己从网上找一些资料, 消化吸收, 再在我的环境当中反复验证, 反复找网上的视频和其他文章

下面就简单整理了开发Web CMDB 已经储备了一些需要的基础知识

HTML 基础知识JavaScript, Jquery, AjaxC#, MVC基础知识LDAP 基础

前端页面

@{ Layout = null;} Sign In

Please sign in

Model逻辑

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.DirectoryServices;namespace TestLDAP.Models{ public class LDAPHelper { private DirectoryEntry de; ///

/// 创建LDAP连接 /// /// /// /// /// public bool OpenConnection(string LDAPPath, string authUsername, string authpwd) { de = new DirectoryEntry(LDAPPath, authUsername, authpwd); object objde = de.NativeObject; if (null == de) { return false; } else if (de.Properties != null && de.Properties.Count > 0) { return true; } return false; } }}

Controller 层

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.DirectoryServices;using TestLDAP.Models;//using System.DirectoryServices.AccountManagement;namespace TestLDAP.Controllers{ public class LdapController : Controller { public ActionResult Login() { return View(); } public ActionResult CheckLogin( string username,string password ) { string uname = username; string upwd = password; string ldappath = "LDAP://DC=contoso,DC=com"; LDAPHelper objldap = new LDAPHelper(); try { bool blresult = objldap.OpenConnection(ldappath, uname, upwd); if (blresult) { //return Json(new { Success = true},JsonRequestBehavior.AllowGet); Session["Currentuser"] = uname; return Json(new { Success = true}); //return RedirectToAction("SearchUser"); } else { return Json(new { Success = false }); } } catch (Exception ex) { string msg = ex.Message; return Json(new { ErrorMsg = msg }); } } public ActionResult SearchUser() { if (Session["Currentuser"] == null) { return Redirect("/Ldap/Login"); } else { return View(); } } }}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Pyhton表白代码——浪漫圣诞节(pythin表白代码)
下一篇:npoi导出 带下拉选择框
相关文章

 发表评论

暂时没有评论,来抢沙发吧~