⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 register.aspx.cs

📁 基于角色的用户验证. 这个程序重点写了四个pages以实现这些功能:增加用户
💻 CS
字号:
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 RolesBasedAthentication.Web
{
	public class Register : Web.PageBase
	{
		protected System.Web.UI.WebControls.TextBox FullName;
		protected System.Web.UI.WebControls.TextBox Email;
		protected System.Web.UI.WebControls.TextBox Password;
		protected System.Web.UI.WebControls.Button Submit;
		protected System.Web.UI.WebControls.Label ErrorMessage;
		protected System.Web.UI.WebControls.TextBox Biography;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Context.User.Identity.IsAuthenticated)
				{
					User user = new User(((SiteIdentity)User.Identity).UserID);

					FullName.Text = user.FullName;
					Email.Text = user.Email;
					Password.Text = user.Password;
					Biography.Text = user.Biography;
				}
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			base.OnInit(e);
			InitializeComponent();
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Submit.Click += new System.EventHandler(this.Submit_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Submit_Click(object sender, System.EventArgs e)
		{
			User user;

			if (Context.User.Identity.IsAuthenticated)
				user = new User(((SiteIdentity)User.Identity).UserID);
			else
				user = new User();

			user.FullName = FullName.Text;
			user.Email = Email.Text;
			user.Password = Password.Text;
			user.Biography = Biography.Text;

			if (Context.User.Identity.IsAuthenticated)
			{
				user.Update();
				Response.Redirect("Default.aspx");
			}
			else
			{
				if (user.Add() == -1)
					ErrorMessage.Visible = true;
				else
				{
					FormsAuthentication.SetAuthCookie( Email.Text, true );
					Response.Redirect("Default.aspx");
				}
			}
		}
	}
}

⌨️ 快捷键说明

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