How i save login username and password usgin Cookie in ASP.NET C#
Any example on how to save username accross pages?
this is my signup, but i want to use cookies to store user username and password, the resaon is because the session expires when the user closes the browser, which throws error on page. So i dont want the user to keep login in all the time thats why i want to store the user username and password the first time the user sign up so that when the user logins in ones the website will keep the user login all the time.
string constr = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("Insert_Users"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
//Get Filename from fileupload control
// string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
//Save images into Images folder
// FileUpload1.SaveAs(Server.MapPath("UserImages/" + filename));
cmd.CommandType = CommandType.StoredProcedure;
// cmd1.Parameters.AddWithValue("@UserImageName", filename);
// cmd1.Parameters.AddWithValue("@UserImagePath", "UserImages/" + filename);
cmd.Parameters.AddWithValue("@Name", txtName.Text.Trim());
cmd.Parameters.AddWithValue("@Email", txtEmail.Text.Trim());
cmd.Parameters.AddWithValue("@UserName", UsrNm);
cmd.Parameters.AddWithValue("@Password", Encrypt(txtPassword.Text.Trim()));
cmd.Parameters.AddWithValue("@BirthDay", txtBirthDay.Text.Trim());
cmd.Parameters.AddWithValue("@Country", ddlCountry.Text.Trim());
cmd.Parameters.AddWithValue("@ImageName", imgname);
cmd.Connection = con;
con.Open();
UserID = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
}
}
string message = string.Empty;
switch (UserID)
{
case -1:
message = "Username already exists.\\Please choose a different username.";
break;
case -2:
message = "Supplied email address has already been used.";
break;
default:
message = "Registration successful, you may now login.";
// SendActivationEmail(UserID);
break;
}
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
}
}
}