在ASP.Net 中使用实现windows登陆的方法. (轉自tainkai的專欄.http://blog.csdn.net/tainkai)
2004-10-20 14:20
966 查看
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);
相关文章推荐
- ASP.Net 中使用实现windows登陆的方法
- 在ASP.Net 中使用实现windows登陆的方法.
- 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【五】——在Web Api中实现Http方法(Put,Post,Delete)
- 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【五】——在Web Api中实现Http方法(Put,Post,Delete)
- 在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(一)----基础类库部分(来源:http://blog.csdn.net/yangjundeng/archive/2005/03/17/321920.aspx)
- 在ASP.NET中重写URL 方法三:在IIS7中使用HttpModule 实现无扩展名的URL重写
- 使用信号实现异步通知机制的例子 http://blog.csdn.net/buaa_shang/article/details/9103155
- asp.net中验证码的实现 (转自http://blog.csdn.net/zhoufoxcn/archive/2007/07/19/1698615.aspx)
- 在ASP.NET中重写URL 方法二:使用HttpModule实现URL重写
- MFC OCX控件实现安全初始化和脚本安全的方法http://blog.csdn.net/xiliang_pan/article/details/8264685
- 快速掌握 Android Studio 中 Gradle 的使用方法 [转http://blog.csdn.net/feelang/article/details/41783317]
- 使用观察者(Observer)实现对象监听 (转自http://blog.csdn.net/kalex)
- (微信公众号开发《一》OAuth2.0网页授权认证获取用户的详细信息,实现自动登陆)http://blog.csdn.net/liaohaojian/article/details/70175835
- 使用Support Library实现ActionBar(http://blog.csdn.net/xyz_lmn/article/details/8132420)
- ASP.NET操作Word文档 http://blog.csdn.net/kaigood/archive/2007/01/18/1486607.aspx
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(4):异步通讯层生成的客户端代理类、使用HTTP GET进行调用
- Asp.Net使用POST方法最简单的实现
- asp.net 中 HttpRequest 中跟URL path 有关的方法和属性 (摘自用怪异的眼光去研究blog)
- ASP.NET 常用技巧学习 (http://blog.csdn.net/JavaProgramers/archive/2007/04/13/1563441.aspx)
- CSharp Tips:应用程序访问集成Windows认证的站点 (Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=11652)