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