日期:2014-05-18 浏览次数:20545 次
public partial class Login : BasePage { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string name = TextBox1.Text; name = name.Replace("'", ""); name = name.Replace("=",""); name = name.Replace("<",""); name = name.Replace(">",""); name = name.Replace("*",""); string password = TextBox2.Text; password.Replace("'",""); password.Replace("=", ""); password.Replace("<", ""); password.Replace(">", ""); password.Replace("*", ""); password = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5"); ZQ_ServicesLogin sl = new ZQ_ServicesLogin(); DataTable dt = sl.Login(name, password); try { if (dt.Rows.Count > 0) { HttpCookie cookie = new HttpCookie("userinfo"); string myID; Session["UserID"] = dt.Rows[0]["ID"].ToString(); myID=Session["UserID"].ToString(); Session["GameID"] = dt.Rows[0]["GameID"].ToString(); Session["PackName"] = dt.Rows[0]["PackName"].ToString(); //Server.Transfer(); cookie.Values["name"] = name; cookie.Values["pwd"]= password; cookie.Expires = DateTime.Now.AddDays(1); Response.AppendCookie(cookie); sl = null; dt.Dispose(); } else { JavaScript.Alert(Page, "用户名或密码输入有误!"); } } catch(Exception ex) { Response.Write(ex); Response.End(); JavaScript.Alert(Page, "登陆失败!"); } Response.Redirect("manage/index.aspx"); } }
public class BasePage: System.Web.UI.Page { public BasePage() { // //TODO: 在此处添加构造函数逻辑 // if (HttpContext.Current.Response.Cookies["userinfo"]["name"] != null && HttpContext.Current.Response.Cookies["userinfo"]["pwd"]!=null) { string name = HttpContext.Current.Response.Cookies["userinfo"]["name"].ToString(); string password = HttpContext.Current.Response.Cookies["userinfo"]["pwd"].ToString(); ZQ_ServicesLogin sl = new ZQ_ServicesLogin(); DataTable dt = sl.Login(name, password); if (dt.Rows.Count > 0) { string myID; Session["UserID"] = dt.Rows[0]["ID"].ToString(); myID = Session["UserID"].ToString(); Session["GameID"] = dt.Rows[0]["GameID"].ToString(); Session["PackName"] = dt.Rows[0]["PackName"].ToString(); sl = null; dt.Dispose(); Response.Redirect("manage/index.aspx