A
download Logon.aspx.cs
Language: C#
LOC: 46
Project Info
common-component-mng-sys - Common Componen...e ...(common-component-mng-sys)
Server: Google
Type: svn
...on‑component‑mng‑sys\trunk\
   AddNewComponent.aspx
   AddNewComponent.aspx.cs
   ADLogin.aspx
   ADLogin.aspx.cs
   ...SearchActionChoice.aspx
   ...rchActionChoice.aspx.cs
   CathayBkRSS.xml
   Comment.aspx
   Comment.aspx.cs
   ...n-component-mng-sys.sln
   ...onent-mng-sys_Model.tgs
   ComponentsList.html
   Default.aspx
   Default.aspx.cs
   Downloading.aspx
   Downloading.aspx.cs
   ErrorPage.htm
   Global.asax
   Logon.aspx
   Logon.aspx.cs
   ManagerMain.aspx
   ManagerMain.aspx.cs
   MasterPage.master
   MasterPage.master.cs
   ReviseComponent.aspx
   ReviseComponent.aspx.cs
   SearchComponent.aspx
   SearchComponent.aspx.cs
   SearchResult.aspx
   SearchResult.aspx.cs
   StatisticsReport.aspx
   StatisticsReport.aspx.cs
   ...oDownloadComponent.aspx
   ...wnloadComponent.aspx.cs
   web.config
   Web.sitemap
   ...ejectReasonAndMail.aspx
   ...ctReasonAndMail.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FormsAuth;

public partial class Logon : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    //UnJ]Login^
    protected void Login_Click(object sender, EventArgs e)
    {       
      string adPath = @"LDAP://DC=Cathaybk, DC=intra, DC=uwccb";    //Path to your LDAP directory server
      LdapAuthentication adAuth = new LdapAuthentication(adPath);

      try
      {
        if(true == adAuth.IsAuthenticated(txtDomain.Text, txtUsername.Text, txtPassword.Text))
        {
          string groups = adAuth.GetGroups();

          //Create the ticket, and add the groups.
          bool isCookiePersistent = chkPersist.Checked;
          FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, 
                    txtUsername.Text,DateTime.Now, DateTime.Now.AddMinutes(60), isCookiePersistent, groups);

          //Encrypt the ticket.
          string encryptedTicket = FormsAuthentication.Encrypt(authTicket);

          //Create a cookie, and then add the encrypted ticket to the cookie as data.
          HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

          if(true == isCookiePersistent)
          authCookie.Expires = authTicket.Expiration;

          //Add the cookie to the outgoing cookies collection.
          Response.Cookies.Add(authCookie);

          //You can redirect now.
         // Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUsername.Text, false));
          Response.Redirect("./Default.aspx");
        }
        else
        {
          errorLabel.Text = "{Ҩä\CˬdϥΪ̦W٩αKXC]Authentication did not succeed. Check user name and password.^";
        }
      }
      catch(Exception ex)
      {
        errorLabel.Text = "{ҥ " + ex.Message;
      }
    }
}

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us