login.aspx.cs

来自「在线商店: C#、SQL和ASP编写」· CS 代码 · 共 85 行

CS
85
字号
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;

namespace StoreOnline
{
	/// <summary>
	/// login 的摘要说明。
	/// </summary>
	public class login : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button btn_login;
		protected System.Web.UI.WebControls.Label Message;
		protected System.Web.UI.WebControls.TextBox password;
		protected System.Web.UI.WebControls.TextBox username;
		protected System.Web.UI.HtmlControls.HtmlImage IMG2;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.btn_login.Click += new System.EventHandler(this.btn_login_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btn_login_Click(object sender, System.EventArgs e)
		{
			if (Page.IsValid == true) 
			{

				StoreOnline.StoreDBO loginDB = new StoreOnline.StoreDBO();
				String tempCartID = loginDB.GetShoppingCartId();
				String userId = loginDB.UserLogin(username.Text, password.Text);

				if (userId != null) 
				{

					loginDB.TransplantShoppingCart(tempCartID, userId);

					//根据用户Id获取用户的详细信息,包括用户名等
					StoreOnline.UserDetails userDetails = loginDB.GetUserDetails(userId);

					//把用户名信息添加到Cookie中
					Response.Cookies["Store_UserName"].Value = userDetails.UserName;			
										
					//把用户名称添加到身份认证凭据中
					FormsAuthentication.RedirectFromLoginPage(userId, true);
					Response.Redirect("Default.aspx");                    		
				}
				else 
				{
					Message.Text = "登录失败";
				}
			}
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?