2011-08-21 55 views
1

存在具有任何身份驗證邏輯的登錄表單。我輸入登錄名和密碼,然後我點擊「登錄」,並得到錯誤「的方法或操作未實現」在這行代碼:FBA身份驗證和安全令牌錯誤

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 

但我自定義成員資格和角色有集會提供者和所有方法都實現了!哪裏出錯?

回答

1

您可以直接從您的自定義成員資格和角色提供者調用基地隸屬函數,如:

Membership.FindUsersByEmail("[email protected]"); 

這些將被默認成員資格提供得到處理,這不會是你的會員供應商,但將成爲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; 
} 
+0

感謝!它運作良好 – NieAR

0

有些事情嘗試:

  • 你通過百磅管理員登記在Web應用程序的供應商?
  • 您是否在web.config中註冊了提供程序?
  • 如果您改用SPClaimsUtility.AuthenticateFormsUser會發生什麼?
+0

1)是2)是3)相同的錯誤 – NieAR