您现在的位置是:首页 >

windows系统登录用户名 在ASP.NET中使用Windows登录[3]

火烧 2022-10-08 00:29:59 1078
在ASP.NET中使用Wi dow 登录[3] ——此文章摘自《ASP NET网络数据库开发实例精解》定价 ¥ 特价 ¥ 详细 gt gt rivate ool Authe ticateU er tr

在ASP.NET中使用Windows登录[3]  

windows系统登录用户名 在ASP.NET中使用Windows登录[3]
    ——此文章摘自《ASP NET网络数据库开发实例精解》定价 ¥ 特价 ¥ 详细>>

    private bool AuthenticateUser(string UserName string Password     string Domain)     {              //设置用户登录成功的标志     bool flag = false;     try     {     int num ;IntPtr ptr ;     //调用Windows登录的API     if(!LogonUser(UserName Domain Password out num ))     {   //返回登录结果     return flag ;     }     //调用 NET中的Windows登录     ptr = new IntPtr(num );     WindowsIdentity identity = new WindowsIdentity(ptr );     WindowsPrincipal principal = new WindowsPrincipal(identity );     HttpContext Current User = principal ;     //设置系统Cookie和重定向页面     FormsAuthentication SetAuthCookie(principal Identity Name false);     FormsAuthentication RedirectFromLoginPage(UserName false);     flag = true;     }     catch (Exception){}     return flag ;     }     单击页面WindowsLogin aspx中的【确定】按钮触发事件UserLoginBtn_Click (object sender System EventArgs e) 该事件调用函数Login(string UserName string Password string Domain)实现Windows登录 事件UserLoginBtn_Click()的程序代码如下     private void UserLoginBtn_Click(object sender System EventArgs e)     {              //验证用户的输入是否为空     if(tDomain Text Trim() Length > && tUserName Text Trim() Length >     && tPassword Text Trim() Length > )     {   //调用函数Login(string UserName string Password string Domain)     //实现Windows登录     if(Login(tUserName Text Trim() tPassword Text Trim()     tDomain Text Trim()) == true)     {   //显示登录成功信息     LoginMsg Text = 登录成功!!! ;     LoginMsg Visible = true;     return;     }     else     {   //显示登录失败信息     LoginMsg Text = 登录失败 请重新输入用户名称 密码及其系统域名!!! ;     LoginMsg Visible = true;     }     }

    }

lishixinzhi/Article/program/net/201311/15542  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码