分別用(Windows/Form/Soap/WebService)實現使用者身分識別驗證(含範例程式碼下載)

來源:互聯網
上載者:User
一).Windows整合身分識別驗證的實現

       1. 說明:

                  Windows身分識別驗證是利用Windows現有的帳號資訊來進行身分識別驗證.

           由IIS自動提供身分識別驗證,比自訂身分識別驗證更安全,但沒有自訂身分識別驗證靈活.

           適用於Web內部應用程式.

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

        2.程式碼範例下載:

             http://www.cnitblog.com/Files/ChengKing/WindowsAuth.rar

(二).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="憑證出錯,請重新輸入";
   }

        2.程式碼範例下載:

                http://www.cnitblog.com/Files/ChengKing/FormsAuth.rar

(三).用Soap實現身分識別驗證

        1.說明

              自訂一個SoapHead儲存使用者名稱和密碼.

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

然後通過調用WebService進行傳入進行驗證, 比較簡單,具體請看程式碼範例.

         2.程式碼範例下載:

                http://www.cnitblog.com/Files/ChengKing/SoapAuth0.rar

(四).用WebService實現身分識別驗證

          1.說明

              調用WebService方法進行身分識別驗證

          2.程式碼範例下載

                 http://www.cnitblog.com/Files/ChengKing/WebAuth.rar

 

下載代碼後運行時要注意一點:

          為了輸入方便,帳號統一,上面四個範例程式碼樣本能夠正確登入的帳號為:

                 UserID :      ChengKing

                 Passward:  123  

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.