簡體   English   中英

FBA身份驗證和安全令牌錯誤

[英]FBA Authentication and Security Token Error

有一個帶有任何驗證邏輯的登錄表單。 我輸入登錄名和密碼,然后單擊“登錄”,並在此代碼行中看到錯誤“未實現方法或操作”:

SecurityToken tk = SPSecurityContext.SecurityTokenForFormsAuthentication
  (
     new Uri(SPContext.Current.Web.Url),
     "MyUserProvider",
     "MyRoleProvider",
     this.txLogin.Text,
     this.txPassword.Text
  );

===============================================

Server Error in '/' Application.

The method or operation is not implemented.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]: The method or operation is not implemented.

Stack Trace: 


[FaultException`1: The method or operation is not implemented.]
   Microsoft.IdentityModel.Protocols.WSTrust.WSTrustChannel.ReadResponse(Message response) +1161013
   Microsoft.IdentityModel.Protocols.WSTrust.WSTrustChannel.Issue(RequestSecurityToken rst, RequestSecurityTokenResponse& rstr) +73
   Microsoft.IdentityModel.Protocols.WSTrust.WSTrustChannel.Issue(RequestSecurityToken rst) +36
   Microsoft.SharePoint.SPSecurityContext.SecurityTokenForContext(Uri context, Boolean bearerToken, SecurityToken onBehalfOf, SecurityToken actAs, SecurityToken delegateTo) +26193297
   Microsoft.SharePoint.SPSecurityContext.SecurityTokenForFormsAuthentication(Uri context, String membershipProviderName, String roleProviderName, String username, String password) +26189452
   Microsoft.SharePoint.IdentityModel.Pages.FormsSignInPage.GetSecurityToken(Login formsSignInControl) +188
   Microsoft.SharePoint.IdentityModel.Pages.FormsSignInPage.AuthenticateEventHandler(Object sender, AuthenticateEventArgs formAuthenticateEvent) +123
   System.Web.UI.WebControls.Login.AttemptLogin() +152

但是我使用自定義成員資格和角色提供程序進行組裝,並且所有方法都已實現! 哪里有錯?

您可能直接從自定義成員資格和角色提供者調用基本成員資格函數,例如:

Membership.FindUsersByEmail("myemail@here.com");

這些將由默認的成員資格提供程序處理,該成員資格提供程序將不是您的成員資格提供程序,而是SPClaimsAuthMembershipProvider。 SPClaimsAuthMembershipProvider沒有實現許多基本方法-它們將返回未實現的異常。

如果要獲取Web應用程序的選定成員資格提供程序以供參考,可以使用以下代碼:

public static string GetMembershipProvider(SPSite site)
{
    // get membership provider of whichever zone in the web app is fba enabled 
    SPIisSettings settings = GetFBAIisSettings(site);
    return settings.FormsClaimsAuthenticationProvider.MembershipProvider;
}

public static SPIisSettings GetFBAIisSettings(SPSite site)
{
    SPIisSettings settings = null;

    // try and get FBA IIS settings from current site zone
    try
    {
        settings = site.WebApplication.IisSettings[site.Zone];
        if (settings.AuthenticationMode == AuthenticationMode.Forms)
            return settings;
    }
    catch 
    { 
        // expecting errors here so do nothing                 
    }

    // check each zone type for an FBA enabled IIS site
    foreach (SPUrlZone zone in Enum.GetValues(typeof(SPUrlZone)))
    {
        try
        {
            settings = site.WebApplication.IisSettings[(SPUrlZone)zone];
            if (settings.AuthenticationMode == AuthenticationMode.Forms)
                return settings;
        }
        catch
        { 
            // expecting errors here so do nothing                 
        }
    }

    // return null if FBA not enabled
    return null;
}

一些嘗試:

  • 您是否通過Cental Admin在Web應用程序中注冊了提供程序?
  • 您是否在web.config中注冊了提供程序?
  • 如果改為使用SPClaimsUtility.AuthenticateFormsUser,會發生什么?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM