login.aspx.cs
来自「基于Asp.net、MS sql sever 2000、C# 论坛系统源码」· CS 代码 · 共 82 行
CS
82 行
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 Stella.BusinessLogic;
using Stella.Utility;
using Stella.Model;
using Stella.Web.ProcessFlow;
using System.Web.Security;
namespace Stella.Web.Pages
{
/// <summary>
/// login 的摘要说明。
/// </summary>
public class login : Container
{
protected System.Web.UI.WebControls.Button singIn;
protected Stella.Web.Controls.Login log;
protected Stella.Web.Controls.LoginError err;
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.singIn.Click += new System.EventHandler(this.singIn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void singIn_Click(object sender, System.EventArgs e)
{
UserLogic ul=new UserLogic();
Guest guest=log.Anonym;
Member user=ul.Login(guest);
if(user==null)
{
log.Visible=false;
err.Visible=true;
err.Message="有错误发生!造成该错误的原因可能是您输入了错误的用户名或密码!";
}
else
{
System.Web.Security.FormsAuthentication.SetAuthCookie(user.Name,log.SaveCookie);
Session["user"]=user;
//保存用户角色
//这里用ticket保存角色,然后传到global的Application_AuthenticateRequest
FormsAuthenticationTicket tic=new FormsAuthenticationTicket(1,user.Name,DateTime.Now,DateTime.Now.AddMinutes(30),log.SaveCookie,user.Role);
string ck=FormsAuthentication.Encrypt(tic);
HttpCookie coo=new HttpCookie(FormsAuthentication.FormsCookieName,ck);
Response.Cookies.Add(coo);
Response.Redirect("index.aspx");
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?