ASP.Net 中使用实现windows登陆的方法
2007-09-28 09:45
706 查看
public bool Login(string UserName, string Password, string Domain)
{
string text1 = Domain.Trim();
string text2 = UserName.Trim();
text2 = text2.Replace("/", @"/");
int num1 = text2.IndexOf('//');
if (num1 != -1)
{
text1 = text2.Substring(0, num1);
text2 = text2.Substring(num1 + 1);
}
else
{
num1 = text2.IndexOf('@');
if (num1 != -1)
{
text1 = text2.Substring(num1 + 1);
text2 = text2.Substring(0, num1);
}
}
return this.authenticateUser(text2, Password.Trim(), text1);
}
private bool authenticateUser(string UserName, string Password, string Domain)
{
bool flag1 = false;
try
{
int num1;
IntPtr ptr1;
if (!WindowsAuth.LogonUser(UserName, Domain, Password, 2, 0, out num1))
{
return flag1;
}
ptr1 = new IntPtr(num1);
WindowsIdentity identity1 = new WindowsIdentity(ptr1);
WindowsPrincipal principal1 = new WindowsPrincipal(identity1);
HttpContext.Current.User = principal1;
FormsAuthentication.SetAuthCookie(principal1.Identity.Name, false);
FormsAuthentication.RedirectFromLoginPage(UserName, false);
flag1 = true;
}
catch (Exception)
{
}
return flag1;
}
[DllImport("advapi32.dll")]
public static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out int phToken);
{
string text1 = Domain.Trim();
string text2 = UserName.Trim();
text2 = text2.Replace("/", @"/");
int num1 = text2.IndexOf('//');
if (num1 != -1)
{
text1 = text2.Substring(0, num1);
text2 = text2.Substring(num1 + 1);
}
else
{
num1 = text2.IndexOf('@');
if (num1 != -1)
{
text1 = text2.Substring(num1 + 1);
text2 = text2.Substring(0, num1);
}
}
return this.authenticateUser(text2, Password.Trim(), text1);
}
private bool authenticateUser(string UserName, string Password, string Domain)
{
bool flag1 = false;
try
{
int num1;
IntPtr ptr1;
if (!WindowsAuth.LogonUser(UserName, Domain, Password, 2, 0, out num1))
{
return flag1;
}
ptr1 = new IntPtr(num1);
WindowsIdentity identity1 = new WindowsIdentity(ptr1);
WindowsPrincipal principal1 = new WindowsPrincipal(identity1);
HttpContext.Current.User = principal1;
FormsAuthentication.SetAuthCookie(principal1.Identity.Name, false);
FormsAuthentication.RedirectFromLoginPage(UserName, false);
flag1 = true;
}
catch (Exception)
{
}
return flag1;
}
[DllImport("advapi32.dll")]
public static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out int phToken);
相关文章推荐
- 在ASP.Net 中使用实现windows登陆的方法. (轉自tainkai的專欄.http://blog.csdn.net/tainkai)
- 在ASP.Net 中使用实现windows登陆的方法.
- 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【五】——在Web Api中实现Http方法(Put,Post,Delete)
- 在ASP.NET中重写URL 方法四:在IIS5和IIS6中使用 ISAPIRewrite 来实现无扩展名的URL重写
- ASP.Net中实现Ajax的几种实现方法之AjaxPro的使用(一)
- 使用ViKey加密狗实现Windows登陆的方法
- asp.net中使用DatagridView的增删改方法具体实现
- ASP.NET使用Cookie简单实现记住登陆状态功能
- 在 ASP.NET 中实现不同角色的用户使用不同登录界面的方法
- ASP.NET中使用UpdatePanel实现局部异步刷新方法和攻略
- Asp.Net使用POST方法最简单的实现
- asp.net中Datalist使用数字分页的实现方法
- 在 ASP.NET 中实现不同角色的用户使用不同登录界面的方法
- 在 ASP.NET 中实现不同角色的用户使用不同登录界面的方法
- asp.net中倒计时自动跳转页面的实现方法(使用javascript)
- C#字符串数组排序 C#排序算法大全 C#字符串比较方法 一个.NET通用JSON解析/构建类的实现(c#) C#处理Json文件 asp.net使用Jquery+iframe传值问题
- 使用asp.net实现防止用户多点登陆
- Asp.Net使用POST方法最简单的实现
- asp.net中使用DatagridView的增删改方法具体实现
- ASP.NET在不同情况下实现单点登陆(SSO)的方法