当前位置: 代码迷 >> .NET分析设计 >> .net中Windows/Form/Soap/WebService身份验证解释解决方法
  详细解决方案

.net中Windows/Form/Soap/WebService身份验证解释解决方法

热度:209   发布时间:2016-05-01 22:34:00.0
.net中Windows/Form/Soap/WebService身份验证解释
今天面试了一家公司,题目中有这个,请问每个具体的详细解释,在线等
------解决方案--------------------
请参考
------解决方案--------------------
http://blog.csdn.net/haojialin/article/details/578777
------解决方案--------------------
(一).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  
  相关解决方案