2011-01-30 145 views
0

我迫切需要爲SP2010網站創建自定義登錄頁面。現在,我知道這可以通過基於聲明的身份驗證和FBA來完成,但經過幾天的工作後,我無法完成,因此我轉而採取了不同的方法。Sharepoint 2010通過其他網站登錄

也許我可以用.NET創建一個前臺網站,這將歡迎用戶和身份驗證。然後,也許我可以爲我的SP2010網站設置「會話狀態」,然後將用戶重定向到sp2010網站。我不知道這是否有可能,但我想學習。

我接受其他建議來爲SP2010創建自定義登錄頁面。

在此先感謝。

回答

0

嗨我必須能夠從SharePoint 2007中的移動設備驗證用戶,我想創建某種自定義登錄。

有可能是這樣做比這更容易/更好的方式,但我首先做了這樣的SharePoint網站,然後我不得不檢查活動目錄。

(User對象是某種在WCF加密的數據,但基本上給了用戶名和密碼)

/// <summary> 
    /// Authenticate whether the user is a user of SharePoint by their username and password 
    /// </summary> 
    /// <param name="LoggedIn">The user that is to be authenticated</param> 
    /// <param name="SharePointSiteAddress">The address of the SharePoint site</param> 
    /// <returns>The name of the user if they are authenticated or null if not</returns> 
    public string AuthenticateSharePointUser_UsePassword(User LoggedIn, string SharePointSiteAddress) 
    { 
     string nameResult = null; 

     try 
     { 

      Authentication authentication = new Authentication(); 

      //Check against active directory first 
      bool isAuthenticated = authentication.AuthenticateUserActiveDirectory(LoggedIn.GetUserName(), LoggedIn.GetPassword()); 

      if (isAuthenticated) 
      { 
       nameResult = authentication.AuthenticateSharePointUserName(LoggedIn.GetUserName(), SharePointSiteAddress); 
      } 
     } 
     catch (Exception ex) 
     { 
      throw new Exception("Authentication Error", ex); 
     } 

     return nameResult; 
    } 

    /// <summary> 
    /// Authenticate that a user exists on SharePoint 
    /// </summary> 
    /// <param name="UserName">The username of the user to check</param> 
    /// <param name="SiteAddress">The address of the site to check user on</param> 
    /// <returns>The name of the user or null if not</returns> 
    public string AuthenticateSharePointUserName(string UserName, string SiteAddress) 
    { 
     string user = null; 

     //Open up the site and get the list 
     using (SPSite site = new SPSite(SiteAddress)) 
     { 
      using (SPWeb web = site.OpenWeb()) 
      { 
       try 
       { 
        user = web.AllUsers[GetFullDomainUserName(UserName)].Name; 
       } 
       catch (Exception) 
       { 
        //Swallow exception from the user not existing 
        user = null; 
       } 
      } 
     } 
     return user; 
    } 

    /// <summary> 
    /// Authenticate the user against active directory 
    /// </summary> 
    /// <param name="UserName">The username that can include the domain name domain\username or just username</param> 
    /// <param name="Password">The password</param> 
    /// <returns>Whether the user has been authenticated</returns> 
    public bool AuthenticateUserActiveDirectory(string UserName, string Password) 
    { 
     //Split on the domain name e.g. domain\... 
     string[] splitUserName = GetFullDomainUserName(UserName).Split('\\'); 
     PrincipalContext context = null; 

     bool authenticated = false; 

     //Provide user domain if there is one to validate against or use current domain thread is running on 
     context = new PrincipalContext(ContextType.Domain, splitUserName[0]); 

     //Now validate against active directory 
     using (context) 
     { 
      authenticated = context.ValidateCredentials(splitUserName[1], Password); 
     } 

     return authenticated; 
    } 

    /// <summary> 
    /// Get a full domain name inclusive username from username given 
    /// if there is not already a domain name in it then attach current domain on this machine 
    /// </summary> 
    /// <param name="UserName">The username provided by user</param> 
    /// <returns>User name in style e.g. domain\----</returns> 
    public static string GetFullDomainUserName(string UserName) 
    { 
     //Split on the domain name e.g. net\356789 
     string[] splitUserName = UserName.Split('\\'); 

     //If the user gave a domain name then use that domain else use the current domain 
     if (splitUserName.Length <= 1) 
     { 
      splitUserName = new string[] { Environment.UserDomainName, UserName }; 
     } 

     return string.Join("\\", splitUserName); 
    } 
1

從長遠來看,我想你會過得更好,詢問的問題,將解決你的問題與CBA和FBA相比,可以在解決方案上共同使用自定義單一標誌。