.Net C#域账号登陆验证
生活随笔
收集整理的這篇文章主要介紹了
.Net C#域账号登陆验证
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//獲取登陸頁輸入的域賬號、密碼
string domainIP = ""; //域IP
string userAccount = ""; //域賬號
string Password = ""; //域賬號密碼
using (DirectoryEntry deUser = new DirectoryEntry(@"LDAP://" + domainIP, userAccount, Password))
{
DirectorySearcher src = new DirectorySearcher(deUser);
src.Filter = "(&(&(objectCategory=person)(objectClass=user))(sAMAccountName=" + userAccount + "))";
src.PropertiesToLoad.Add("cn");
src.SearchRoot = deUser;
src.SearchScope = SearchScope.Subtree;
SearchResult result = src.FindOne();
if (result != null)//驗證成功
{
DirectoryEntry de = result.GetDirectoryEntry();
string userID = de.Username;
#region 域賬號驗證通過后判斷是否用戶在本系統中
var existUser = new DAL.Maintain.UserOP().GetData(userID);
if (existUser == null)
{
ViewBag.ErrorInfo = "提示:您未開通系統的權限,請聯系管理員。<br/>You have no access to the system, please contact the administrator!";
return View();
}
#endregion
FormsAuthentication.SetAuthCookie(userID, false);
Session.Add("UserID", userID);
Logger.DefaultLog.Info("登陸sessionUserID:" + Session["UserID"].ToString());
if (string.IsNullOrEmpty(ReturnUrl))
{
return Redirect(Url.Action("Index", "Home"));
}
else
{
//...
}
}
else
{
ViewBag.ErrorInfo = "提示:登錄失敗: 未知的用戶名或錯誤密碼。<br/>Account or Password is incorrect!";
return View();
}
}
總結
以上是生活随笔為你收集整理的.Net C#域账号登陆验证的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python中判断字符是否为字母、数字、
- 下一篇: CNN中常用的卷积核:锐化卷积核模板