ClientFormsAuthenticationMembershipProvider 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
以用戶端應用程式服務啟用表單驗證。
public ref class ClientFormsAuthenticationMembershipProvider : System::Web::Security::MembershipProvider
public class ClientFormsAuthenticationMembershipProvider : System.Web.Security.MembershipProvider
type ClientFormsAuthenticationMembershipProvider = class
inherit MembershipProvider
Public Class ClientFormsAuthenticationMembershipProvider
Inherits MembershipProvider
- 繼承
範例
下列範例程式碼示範如何使用這個方法來使用 IClientFormsAuthenticationCredentialsProvider 實作來驗證使用者。
private bool ValidateUsingCredentialsProvider()
{
bool isAuthorized = false;
try
{
ClientFormsAuthenticationMembershipProvider authProvider =
System.Web.Security.Membership.Provider as
ClientFormsAuthenticationMembershipProvider;
// Call ValidateUser with empty strings in order to display the
// login dialog box configured as a credentials provider.
isAuthorized = authProvider.ValidateUser(String.Empty, String.Empty);
}
catch (System.Net.WebException)
{
MessageBox.Show("Unable to access the authentication service.",
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
if (!isAuthorized)
{
MessageBox.Show("Unable to authenticate.", "Not logged in",
MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
return isAuthorized;
}
Private Function ValidateUsingCredentialsProvider() As Boolean
Dim isAuthorized As Boolean = False
Try
Dim authProvider As ClientFormsAuthenticationMembershipProvider = _
CType(System.Web.Security.Membership.Provider, _
ClientFormsAuthenticationMembershipProvider)
' Call ValidateUser with empty strings in order to display the
' login dialog box configured as a credentials provider.
isAuthorized = authProvider.ValidateUser(String.Empty, String.Empty)
Catch ex As System.Net.WebException
MessageBox.Show("Unable to access the authentication service.", _
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
If Not isAuthorized Then
MessageBox.Show("Unable to authenticate.", "Not logged in", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Application.Exit()
End If
Return isAuthorized
End Function
備註
您可以使用用戶端應用程式服務,使用表單驗證來驗證使用者。 若要啟用表單驗證,您可以將應用程式設定為使用 類別 ClientFormsAuthenticationMembershipProvider 。
設定之後,您可以呼叫 方法來 static
Membership.ValidateUser 驗證使用者,此方法會在內部呼叫 ClientFormsAuthenticationMembershipProvider.ValidateUser(String, String) 方法。
表單驗證需要使用者透過應用程式所提供的登入控制項來指定其認證。 您可以擷取認證,並將其傳遞至 Membership.ValidateUser 方法。 您也可以傳入空字串或使用 null
認證提供者。 認證提供者是 IClientFormsAuthenticationCredentialsProvider 應用程式組態檔中指定的實作。 您通常會實 IClientFormsAuthenticationCredentialsProvider.GetCredentials 作 方法來顯示登入對話方塊,並傳回填入 ClientFormsAuthenticationCredentials 的物件。 您可透過使用認證提供者在多個應用程式之間分享單一登入對話方塊。
方法會 ClientFormsAuthenticationMembershipProvider.ValidateUser 透過 屬性所 ServiceUri 指示的登入服務來驗證使用者。 屬性的值 ServiceUri 通常是從應用程式組態檔擷取,以及其他組態值。
如果使用者成功驗證,服務提供者會將 static
Thread.CurrentPrincipal 屬性設定為新的 ClientRolePrincipal 物件,其中包含包含使用者資訊的新 ClientFormsIdentity 物件。 ClientRoleProvider如果 已為您的應用程式設定 ,您可以使用 ClientRolePrincipal 物件從角色服務擷取使用者角色資訊。
您可以透過 屬性擷取目前 ClientFormsAuthenticationMembershipProvider 實例的 static
Membership.Provider 參考。 您可以使用成員資格提供者參考直接呼叫 ClientFormsAuthenticationMembershipProvider.ValidateUser 方法。 此外,您將需要成員資格提供者參考來呼叫 Logout 方法,這在基類中 MembershipProvider 無法使用。
您無法使用 ClientFormsAuthenticationMembershipProvider 類別來建立、刪除或修改成員資格資訊。 若要建立、刪除或修改使用者,您必須變更伺服器上的登入服務組態。
建構函式
ClientFormsAuthenticationMembershipProvider() |
初始化 ClientFormsAuthenticationMembershipProvider 類別的新執行個體。 |
屬性
ApplicationName |
這個屬性不是由這個類別所使用。 |
Description |
取得簡短、易讀的描述,適合顯示在管理工具或其他使用者介面 (UI) 中。 (繼承來源 ProviderBase) |
EnablePasswordReset |
這個屬性不是由這個類別所使用。 |
EnablePasswordRetrieval |
這個屬性不是由這個類別所使用。 |
MaxInvalidPasswordAttempts |
這個屬性不是由這個類別所使用。 |
MinRequiredNonAlphanumericCharacters |
這個屬性不是由這個類別所使用。 |
MinRequiredPasswordLength |
這個屬性不是由這個類別所使用。 |
Name |
取得用來在設定期間代表提供者的易記名稱。 (繼承來源 ProviderBase) |
PasswordAttemptWindow |
這個屬性不是由這個類別所使用。 |
PasswordFormat |
這個屬性不是由這個類別所使用。 |
PasswordStrengthRegularExpression |
這個屬性不是由這個類別所使用。 |
RequiresQuestionAndAnswer |
這個屬性不是由這個類別所使用。 |
RequiresUniqueEmail |
這個屬性不是由這個類別所使用。 |
ServiceUri |
取得或設定驗證服務的 URI。 |
方法
事件
UserValidated |
在驗證使用者時發生。 |
ValidatingPassword |
當建立使用者、變更密碼或重設密碼時發生。 (繼承來源 MembershipProvider) |
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應