C#开发中Windows域认证登录2(扩展吉日嘎拉GPM系统)
2013-11-30 18:32
477 查看
原文地址:http://www.cuiwenyuan.com/shanghai/post/Windows-AD-Logon-Intergrated-into-Jirigala-GPM-DotNet-Business.html
上午写了一篇《C#开发中Windows域认证登录》,然后跟吉日嘎拉沟通了一下,还是把这个Windows AD用户登录的功能扩展到DotNet.Business中,重新命名为LDAP方式的登录,因为需要引用System.DirectoryServices,暂时用不到此功能的朋友,可以exclude此文件(DotNet.Business\WebUtilities\Utilities.LogOnLDAP.cs)。
前端的登录文件-SigninLDAP.aspx,代码较多可参考Signin.aspx。
上午写了一篇《C#开发中Windows域认证登录》,然后跟吉日嘎拉沟通了一下,还是把这个Windows AD用户登录的功能扩展到DotNet.Business中,重新命名为LDAP方式的登录,因为需要引用System.DirectoryServices,暂时用不到此功能的朋友,可以exclude此文件(DotNet.Business\WebUtilities\Utilities.LogOnLDAP.cs)。
//----------------------------------------------------------------- // All Rights Reserved , Copyright (C) 2013 , Hairihan TECH, Ltd . //----------------------------------------------------------------- using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Text; using System.Web; using System.Web.Caching; using System.Web.Security; using System.DirectoryServices; using DotNet.Utilities; namespace DotNet.Business { /// <summary> /// LDAP登录功能相关部分 /// </summary> public partial class Utilities { // LDAP域用户登录部分:包括Windows AD域用户登录 #region public static BaseUserInfo LogOnByLDAP(string domain, string lDAP, string userName, string password, string permissionCode, bool persistCookie, bool formsAuthentication, out string statusCode, out string statusMessage) /// <summary> /// 验证LDAP用户 /// </summary> /// <param name="domain">域</param> /// <param name="lDAP">LDAP</param> /// <param name="userName">域用户名</param> /// <param name="password">域密码</param> /// <param name="permissionCode">权限编号</param> /// <param name="persistCookie">是否保存密码</param> /// <param name="formsAuthentication">表单验证,是否需要重定位</param> /// <param name="statusCode"></param> /// <param name="statusMessage"></param> /// <returns></returns> public static BaseUserInfo LogOnByLDAP(string domain, string lDAP, string userName, string password, string permissionCode, bool persistCookie, bool formsAuthentication, out string statusCode, out string statusMessage) { DirectoryEntry dirEntry = new DirectoryEntry(); dirEntry.Path = lDAP; dirEntry.Username = domain + "\\" + userName; dirEntry.Password = password; dirEntry.AuthenticationType = AuthenticationTypes.Secure; try { DirectorySearcher dirSearcher = new DirectorySearcher(dirEntry); dirSearcher.Filter = String.Format("(&(objectClass=user)(samAccountName={0}))", userName); System.DirectoryServices.SearchResult result = dirSearcher.FindOne(); if (result != null) { // 统一的登录服务 DotNetService dotNetService = new DotNetService(); BaseUserInfo userInfo = dotNetService.LogOnService.LogOnByUserName(Utilities.GetUserInfo(), userName, out statusCode, out statusMessage); // 检查身份 if (statusCode.Equals(Status.OK.ToString())) { userInfo.IPAddress = GetIPAddressId(); bool isAuthorized = true; // 用户是否有哪个相应的权限 if (!string.IsNullOrEmpty(permissionCode)) { isAuthorized = dotNetService.PermissionService.IsAuthorized(userInfo, permissionCode, null); } // 有相应的权限才可以登录 if (isAuthorized) { if (persistCookie) { // 相对安全的方式保存登录状态 // SaveCookie(userName, password); // 内部单点登录方式 SaveCookie(userInfo); } else { RemoveUserCookie(); } LogOn(userInfo, formsAuthentication); } else { statusCode = Status.LogOnDeny.ToString(); statusMessage = "访问被拒绝、您的账户没有后台管理访问权限。"; } } return userInfo; } else { statusCode = Status.LogOnDeny.ToString(); statusMessage = "应用系统用户不存在,请联系管理员。"; return null; } } catch (Exception e) { //Logon failure: unknown user name or bad password. statusCode = Status.LogOnDeny.ToString(); statusMessage = "域服务器返回信息" + e.Message.Replace("\r\n", ""); return null; } } #endregion } }
前端的登录文件-SigninLDAP.aspx,代码较多可参考Signin.aspx。
相关文章推荐
- C#开发中Windows域认证登录2016(扩展吉日嘎拉GPM系统V4.2)
- Windows自定义登录认证开发-C#
- C#Winform开发,Listview根据文件路径或扩展名显示系统文件图标
- C# 分层开发的案例 学生管理系统 实现用户的登录和修改密码
- Oracle EBS系统短信认证登录开发
- C# .NET 可灵活配置登录窗体、主窗体的快速信息管理系统开发架构参考
- C#Winform开发,Listview根据文件路径或扩展名显示系统文件图标
- C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 - 检查版本升级、检查登录超时
- C#系统开发登录窗体在MDI窗体之前显示
- C# .NET 可灵活配置登录窗体、主窗体的快速信息管理系统开发架构参考
- C# .NET 可灵活配置登录窗体、主窗体的快速信息管理系统开发架构参考
- C#_会员管理系统:开发一(用户登录)
- 通用权限管理系统组件 (GPM - General Permissions Manager) 中实现统一身份认证(Single Sign On,单点登录)附源码
- c#小系统开发之登录 注册
- 老程序员边学习C#边开发智慧医疗系统---系统登录001
- C#人事管理系统开发(5)登录模块设计
- Unity3D开发小贴士(七)Lua里扩展C#对象
- 用C#开发Windows服务监控系统使用
- 清理吉日嘎拉走火入魔C#.NET通用权限管理系统组件表数据的脚本方法参考
- c#开发仓储销售管理平台--系统需求分析2