Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends..
I want to do from login authentication with sql server,cockies and ticket so pls help me to solve problem..
after checkin username and password not open athenticated aspx file.. username and password are correct still not opened.. i am using cockies and ticket method..
i think problem in web.config..

please help me.. Dost

This is code..


C#
public partial class Login : System.Web.UI.Page
{
    
   protected void BtnLogin_Click(object sender, EventArgs e)
    
   {
        try
        {
            if (IsValid)
            {
                SqlParameter[] parameterValues = new SqlParameter { SqlHelper.MakeParam("@LoginID", TxtLoginID.Text), SqlHelper.MakeParam("@Password", TxtPassword.Text) };
                SqlConnection connection = null;
                {
                    try
                    {
                        connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BESTConnection"].ConnectionString);
                        connection.Open();
                        SqlDataReader reader = SqlHelper.ExecuteReader(connection, "SP_AuthenticateInternalUsers", parameterValues);
                        {
                            if (reader.HasRows)
                            {
                                reader.Read();
                                string name = reader["Name"].ToString();
                                string userData = reader["InternalUserId"].ToString() + "|" + reader["AccessLevel"].ToString() + "|" + this.TxtLoginID.Text;
                                reader.Close();
                                connection.Close();
                                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, name, DateTime.Now, DateTime.Now.AddMinutes(30.0), false, userData, FormsAuthentication.FormsCookiePath);
                                string str3 = FormsAuthentication.Encrypt(ticket);
                                Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, str3));
                                Response.Redirect(FormsAuthentication.GetRedirectUrl(name,false),false);
                            }
                                                            else
                                {
                                    LblMsg.Text = "Invalid Login ID or Password";
                                }
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        BESTPISUtilityClass.ShowException(this.Page, exception.Message.ToString());
                       
                    }
                }
            }
        }
        catch (Exception exception2)
        {
            BESTPISUtilityClass.ShowException(this.Page, exception2.Message.ToString());            
        }
    }


   protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           if (Context.User.Identity.Name.Length > 0)
           {
               lblReason.Text = "<em>You do not have sufficient privilege to access the page that your were attempting to view.</em>";
           }
           else if (!string.IsNullOrEmpty(Request.QueryString["ref"]) && (Request.QueryString["ref"].ToLower() == "logout"))
           {
               lblReason.Text = lblReason.Text + "<em>You have logged out.</em>";
           }
           else
           {
               lblReason.Text = lblReason.Text + "<em>You are not currently authenticated.</em>";
           }
       }
   }
       
}
Posted

1 solution

Why re-invent the wheel?
Why not just use the Membership Provider class[^] and it will all work...
 
Share this answer
 
Comments
Mehdi Gholam 31-Oct-11 5:51am    
Nice, 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900