分别用(Windows/Form/Soap/WebService)实现用户身份验证

80酷酷网    80kuku.com

  web|window

(一).Windows集成身份验证的实现

       1. 说明:

                  Windows身份验证是利用Windows现有的账号信息来进行身份验证.

           由IIS自动提供身份验证,比自定义身份验证更安全,但没有自定义身份验证灵活.

           适用于Web内部应用程序.

                 在Web.Config中配置:  <authentication mode="Windows" />

 

(二).Form身份验证

       1.说明: 使用基于窗体的验证方式. 在Web.Config中配置:

<authentication mode="Forms">
     <forms name=".ASPXCOOKIEDEMO"
       protection="All"
       loginUrl="login.aspx"
       timeout="20"
       path="/">
      <credentials passwordFormat="Clear">
        <user name="ChengKing" password="123"/>
      </credentials> 
     </forms>
 </authentication>  

其中 <user name="ChengKing" password="123"/>为自定义配置用户登录信息
在代码中这样取得此数据:

   if(FormsAuthentication.Authenticate(txtUser.Text,txtPwd.Text))
   {
             FormsAuthentication.RedirectFromLoginPage(txtUser.Text,false);
   }
   else
   {
             errMsg.Text="凭证出错,请重新输入";
   }

 

(三).用Soap实现身份验证

        1.说明

              自定义一个SoapHead存储用户名和密码.

 public class SOAPAuthHeader:SoapHeader
 {
       public string UserName;
       public string UserPwd;
 }

然后通过调用WebService进行传入进行验证, 比较简单,具体请看代码示例.

(四).用WebService实现身份验证

          1.说明

              调用SebService方法进行身份验证

下载代码后运行时要注意一点:

          为了输入方便,账号统一,上面四个示例代码示例能够正确登录的账号为:

                 UserID :      ChengKing

                 Passward:  123  

               

 

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: