2014-02-25 25 views
0

請一些身體幫助我。我會在我的網站上創建登錄頁面,這是我的視圖代碼。把登錄代碼在sitecore功能

 <asp:TextBox CssClass="input-block-level" placeholder="Email address" runat="server" ID="txtUser"/> 

    <asp:TextBox runat="server" ID="txtPass" TextMode="Password" CssClass="input-block-level" placeholder="password"/> 

    <asp:Button runat="server" ID="btnlogin" CssClass="btn btn-large btn-primary" Text="Sign in" OnClick="btnlogin_Click"/> 

任何意見表示讚賞。謝謝。

+0

[sitecore make a login page]的可能重複(http://stackoverflow.com/questions/16184251/sitecore-making-a-login-page) – jammykam

回答

3

您需要Sitecore中已有用戶,這是登錄的代碼,如果您登錄,則返回true;否則爲false;

/// <summary> 
    /// Logins the specified username. 
    /// </summary> 
    /// <param name="username">The username.</param> 
    /// <param name="password">The password.</param> 
    /// <returns><c>true</c> if user login is ok; otherwise, <c>false</c></returns> 
    public static bool Login(string username, string password) 
    { 
     username = string.Format(@"{0}\{1}", "yourDomain", username); 
     try 
     { 
      if (Sitecore.Security.Authentication.AuthenticationManager.Login(username, password)) 
      { 
       return true; 
      } 
     } 
     catch (System.Security.Authentication.AuthenticationException exception) 
     { 
      Sitecore.Diagnostics.Log.Error(exception.StackTrace+" login error",""); 
     } 

     return false; 
    }