protected void Page_Load(object sender, EventArgs e) { Utlities u = new Utlities(); u.RefreshLogTemp(HttpContext.Current.User.Identity.Name); // string chat = // u.GetStringValue("SELECT top 1 ChatText FROM [dbo].[ChatRoom] where ReadBy like '%" + // HttpContext.Current.User.Identity.Name + "%' order by Id desc"); // if (chat.Length > 0) // lbchat.Text = @"<div id=""frameContainer"" style=""overflow: hidden; width: 280px; height: 45px; margin-top: -40px;""> // <iframe src=""../Utilities/ChatContain.aspx"" scrolling=no style=""width: 280px; height: 60px;margin-left:0px; margin-top: -16px; padding-left: 0px;border-left-width: 0px; border-right-width: 0px;""></iframe> // </div>"; //else //{ // lbchat.Text = ""; //} // PageAccess(); }
protected void LoginStatus_LoggedOut(object sender, EventArgs e) { Session.Clear(); Session.Abandon(); var ticket1 = new FormsAuthenticationTicket("", true, 0); var hash1 = FormsAuthentication.Encrypt(ticket1); var cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, hash1); cookie1.Expires = DateTime.Now.AddMinutes(0); if (ticket1.IsPersistent) { cookie1.Expires = ticket1.Expiration; } Response.Cookies.Add(cookie1); Utlities u = new Utlities(); u.LogoutUser(HttpContext.Current.User.Identity.Name); }
protected void btnSingIn_Click(object sender, EventArgs e) { try { Utlities u = new Utlities(); List <string[]> parameters = new List <string[]>(); parameters.Add(new string[] { "user", txtusername.Text }); parameters.Add(new string[] { "pass", txtuserpass.Text }); DataTable DTOU = u.ReturnTableWithParameter("select [UserName],[Password],'Admin' as TypeName from AppUser where [UserName]=@user And [Password]=@pass", parameters); if (DTOU.Rows.Count > 0) { if (DTOU.Rows[0]["UserName"].ToString() == txtusername.Text && DTOU.Rows[0]["Password"].ToString() == txtuserpass.Text) { var EXPIRETIMELIMIT = Convert.ToDouble(ConfigurationManager.AppSettings["EXPIRETIMELIMIT"]); FormsAuthentication.Initialize(); FormsAuthentication.HashPasswordForStoringInConfigFile(txtuserpass.Text.ToString(), "md5"); string ip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (string.IsNullOrEmpty(ip)) { ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } var roles = new StringBuilder(); //string logip = u.SaveLogin(txtusername.Text, ip, DTOU.Rows[0]["TypeName"].ToString()); //if (logip != "") //{ // string message = "Already Login " + txtusername.Text + " From " + logip; // var page = HttpContext.Current.Handler as Page; // if (page != null) // { // message = message.Replace("'", "\'"); // ScriptManager.RegisterStartupScript(page, page.GetType(), "err_msg", // "alert('" + message + "');", true); // } // return; //} //for (var i = 0; i < DTOU.Rows.Count; i++) //{ // roles.Append(DTOU.Rows[i]["RoleName"].ToString()); //} var ticket = new FormsAuthenticationTicket(1, txtusername.Text.ToString(), DateTime.Now, DateTime.Now.AddMinutes(EXPIRETIMELIMIT), true, roles.ToString(), FormsAuthentication.FormsCookiePath); var hash = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash); /*We have to set the cookie expire time manually,its not working which we set in the parameter of the FormsAuthenticationTicket's constructor .*/ cookie.Expires = DateTime.Now.AddMinutes(EXPIRETIMELIMIT); if (ticket.IsPersistent) { cookie.Expires = ticket.Expiration; } Response.Cookies.Add(cookie); // DateTime bdate = new DateTime(); // if (DTOU.Rows[0]["Emp_Job_Type"].ToString() == "Emp") // { // bdate = Convert.ToDateTime(u.GetStringValue(@"select dob from PayEmployeesBasicInfoes // a join PayEmployeeJobDetails b on a.EmpId=b.EmpId where b.UserName='******'")); // } // else // { // bdate = // Convert.ToDateTime( // u.GetStringValue(@"select dob from AgentBasicInfo a join AgentJobDetails b on // a.AgentId=b.AgentId where b.UserName='******'")); // } // if (DTOU.Rows[0]["Emp_Job_Type"].ToString() != "SE") // { // if (bdate.Day == DateTime.Now.Day && bdate.Month == DateTime.Now.Month) // { // Response.Redirect("WelcomeWish.aspx"); // } // else // { // Response.Redirect("HomeUI.aspx"); // } // } // else // { Response.Redirect("HomeUI.aspx"); //} } } else { string message = "Username or Password Incorrect."; var page = HttpContext.Current.Handler as Page; if (page != null) { message = message.Replace("'", "\'"); ScriptManager.RegisterStartupScript(page, page.GetType(), "err_msg", "alert('" + message + "');", true); } } } catch (Exception ex) { Response.Write(ex.ToString()); Response.Write("\n " + ex.Message); } }