signin.ascx.cs
来自「三层架构的.net源码三层架构的.net源码」· CS 代码 · 共 81 行
CS
81 行
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
namespace MyStarterKit.Portal.Web
{
/// <summary>
/// SignIn 的摘要说明。
/// 用登录模块
/// </summary>
public class SignIn : PortalModuleControl
{
protected System.Web.UI.WebControls.TextBox email;
protected System.Web.UI.WebControls.TextBox password;
protected System.Web.UI.WebControls.CheckBox RememberCheckbox;
protected System.Web.UI.WebControls.ImageButton SigninBtn;
protected System.Web.UI.WebControls.Label Message;
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.SigninBtn.Click += new System.Web.UI.ImageClickEventHandler(this.SigninBtn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
/// <summary>
/// 登录
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SigninBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
// Attempt to Validate User Credentials using UsersDB
// 通过UsersDB类尝试并验证用户是否合法
UsersDB accountSystem = new UsersDB();
String userId = accountSystem.Login(email.Text, PortalSecurity.Encrypt(password.Text));
if ((userId != null) && (userId != ""))
{
// Use security system to set the UserID within a client-side Cookie
// 为给定的 userName 和 createPersistentCookie 创建身份验证票,并将其附加到 Cookie 的传出响应的集合。它不执行重定向。
// 以email为用户标识名称建立用户标识时同时触发Global.asax.cs中的Application_AuthenticateRequest事件
FormsAuthentication.SetAuthCookie(email.Text, RememberCheckbox.Checked);
// Redirect browser back to originating page
// 从定向到起始页
Response.Redirect(Request.ApplicationPath);
}
else
{
Message.Text = "<" + "br" + ">登录失败!" + "<" + "br" + ">";
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?