对于一个后端管理系统,最重要内容之一的就是登陆页了,无论是安全验证、用户在线记录、相关日志记录、单用户或多用户使用帐号控制等,都是在这个页面进行处理的。

  1、在解决方案中创建一个Web项目,并将它设置为启动项

  

  2、添加引用

  

  

  

  3、添加WebManage文件夹与Login.aspx文件

  

  

  4、添加登陆页面HTML代码  

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="Solution.Web.Managers.WebManage.Login" %>

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>从零开始编写自己的C#框架——后端管理系统</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="Css/login.css" />
<script type="text/javascript">
function Random(n) { return (Math.floor(Math.random() * n)); }; function AjaxRnd() { return new Date().getTime() + '' + Random(); }; function ShowKey() {
document.getElementById("img_verifycode").src = "Base/Vcode.ashx?a=" + AjaxRnd();
};
</script>
</head>
<body>
<!--CENTER开始-->
<div class="login-container">
<form id="form1" runat="server">
<div class="login-header">
<h3>
Login</h3>
</div>
<div id="login-content" class="clearfix">
<div>
<label>
用户名</label>
<div>
<asp:TextBox runat="server" ID="txtusername" CssClass="input w92" />
</div>
<label>
密码</label>
<div>
<asp:TextBox runat="server" ID="txtpass" CssClass="input w92" TextMode="Password" />
</div>
<label>
验证码</label>
<div>
<asp:TextBox runat="server" ID="txtcode" CssClass="input w100 fl" />
<asp:Image ID="img_verifycode" runat="server" onclick="ShowKey();" ToolTip="更换验证码"
ImageUrl="Base/Vcode.ashx" />
<div class="fc"></div>
</div>
</div>
<div>
<asp:Button ID="BtnLogin" CssClass="btn" runat="server" OnClick="BtnLogin_Click"
Text="登陆" />
</div>
</div>
</form>
</div>
<!--CENTER结束-->
</body>
</html>

  css样式在本文后面的解决方案中有

  浏览一下效果

  

  5、后端管理系统登陆验证流程图

  我们根据下面的流程图来编写登陆页代码

  6、添加在线列表数据表并修改管事员表相关字段

  执行下面SQL语句

 /****** Object:  Table [dbo].[Manager]    Script Date: 2014/6/4 22:27:52  ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Manager]') and OBJECTPROPERTY(id, N'IsUserTable') = )
drop table [dbo].[Manager]
GO /****** Object: Table [dbo].[Manager] Script Date: 2014/6/4 22:27:52 ******/
CREATE TABLE [dbo].[Manager] (
[Id] [int] IDENTITY (, ) NOT NULL,
[LoginName] [nvarchar] () NOT NULL,
[LoginPass] [nvarchar] () NOT NULL,
[LoginTime] [datetime] NOT NULL,
[LoginIp] [nvarchar] () NOT NULL,
[LoginCount] [int] NOT NULL,
[CreateTime] [datetime] NOT NULL,
[UpdateTime] [datetime] NOT NULL,
[IsMultiUser] [tinyint] NOT NULL,
[Branch_Id] [int] NOT NULL,
[Branch_Code] [nvarchar] () NOT NULL,
[Branch_Name] [nvarchar] () NOT NULL,
[Position_Id] [nvarchar] () NOT NULL,
[Position_Name] [nvarchar] () NOT NULL,
[IsWork] [tinyint] NOT NULL,
[IsEnable] [tinyint] NOT NULL,
[CName] [nvarchar] () NOT NULL,
[EName] [nvarchar] () NOT NULL,
[PhotoImg] [nvarchar] () NOT NULL,
[Sex] [nvarchar] () NOT NULL,
[Birthday] [nvarchar] () NOT NULL,
[NativePlace] [nvarchar] () NOT NULL,
[NationalName] [nvarchar] () NOT NULL,
[Record] [nvarchar] () NOT NULL,
[GraduateCollege] [nvarchar] () NOT NULL,
[GraduateSpecialty] [nvarchar] () NOT NULL,
[Tel] [nvarchar] () NOT NULL,
[Mobile] [nvarchar] () NOT NULL,
[Email] [nvarchar] () NOT NULL,
[Qq] [nvarchar] () NOT NULL,
[Msn] [nvarchar] () NOT NULL,
[Address] [nvarchar] () NOT NULL,
[Content] [ntext] NOT NULL,
[Manager_Id] [int] NOT NULL,
[Manager_CName] [nvarchar] () NOT NULL
) ON [PRIMARY]
GO ALTER TABLE [dbo].[Manager] WITH NOCHECK ADD
CONSTRAINT [PK_Manager] PRIMARY KEY CLUSTERED
(
[Id]
) ON [PRIMARY]
GO ALTER TABLE [dbo].[Manager] ADD
CONSTRAINT [DF_Manager_LoginName] DEFAULT ('') FOR [LoginName],
CONSTRAINT [DF_Manager_LoginPass] DEFAULT ('') FOR [LoginPass],
CONSTRAINT [DF_Manager_LoginTime] DEFAULT (getdate()) FOR [LoginTime],
CONSTRAINT [DF_Manager_LoginIp] DEFAULT ('') FOR [LoginIp],
CONSTRAINT [DF_Manager_LoginCount] DEFAULT () FOR [LoginCount],
CONSTRAINT [DF_Manager_CreateTime] DEFAULT (getdate()) FOR [CreateTime],
CONSTRAINT [DF_Manager_UpdateTime] DEFAULT (getdate()) FOR [UpdateTime],
CONSTRAINT [DF_Manager_IsMultiUser] DEFAULT () FOR [IsMultiUser],
CONSTRAINT [DF_Manager_Branch_Id] DEFAULT () FOR [Branch_Id],
CONSTRAINT [DF_Manager_Branch_Code] DEFAULT ('') FOR [Branch_Code],
CONSTRAINT [DF_Manager_Branch_Name] DEFAULT ('') FOR [Branch_Name],
CONSTRAINT [DF_Manager_Position_Id] DEFAULT ('') FOR [Position_Id],
CONSTRAINT [DF_Manager_Position_Name] DEFAULT ('') FOR [Position_Name],
CONSTRAINT [DF_Manager_IsWork] DEFAULT () FOR [IsWork],
CONSTRAINT [DF_Manager_IsEnable] DEFAULT () FOR [IsEnable],
CONSTRAINT [DF_Manager_CName] DEFAULT ('') FOR [CName],
CONSTRAINT [DF_Manager_EName] DEFAULT ('') FOR [EName],
CONSTRAINT [DF_Manager_PhotoImg] DEFAULT ('') FOR [PhotoImg],
CONSTRAINT [DF_Manager_Sex] DEFAULT ('') FOR [Sex],
CONSTRAINT [DF_Manager_Birthday] DEFAULT ('') FOR [Birthday],
CONSTRAINT [DF_Manager_NativePlace] DEFAULT ('') FOR [NativePlace],
CONSTRAINT [DF_Manager_NationalName] DEFAULT ('') FOR [NationalName],
CONSTRAINT [DF_Manager_Record] DEFAULT ('') FOR [Record],
CONSTRAINT [DF_Manager_GraduateCollege] DEFAULT ('') FOR [GraduateCollege],
CONSTRAINT [DF_Manager_GraduateSpecialty] DEFAULT ('') FOR [GraduateSpecialty],
CONSTRAINT [DF_Manager_Tel] DEFAULT ('') FOR [Tel],
CONSTRAINT [DF_Manager_Mobile] DEFAULT ('') FOR [Mobile],
CONSTRAINT [DF_Manager_Email] DEFAULT ('') FOR [Email],
CONSTRAINT [DF_Manager_Qq] DEFAULT ('') FOR [Qq],
CONSTRAINT [DF_Manager_Msn] DEFAULT ('') FOR [Msn],
CONSTRAINT [DF_Manager_Address] DEFAULT ('') FOR [Address],
CONSTRAINT [DF_Manager_Content] DEFAULT ('') FOR [Content],
CONSTRAINT [DF_Manager_Manager_Id] DEFAULT () FOR [Manager_Id],
CONSTRAINT [DF_Manager_Manager_CName] DEFAULT ('') FOR [Manager_CName]
GO CREATE INDEX [IX_Manager__LoginName] ON [dbo].[Manager]([LoginName]) ON [PRIMARY]
GO CREATE INDEX [IX_Manager__LoginTime] ON [dbo].[Manager]([LoginTime]) ON [PRIMARY]
GO CREATE INDEX [IX_Manager__CreateTime] ON [dbo].[Manager]([CreateTime]) ON [PRIMARY]
GO CREATE INDEX [IX_Manager__UpdateTime] ON [dbo].[Manager]([UpdateTime]) ON [PRIMARY]
GO CREATE INDEX [IX_Manager__Branch_Id] ON [dbo].[Manager]([Branch_Id]) ON [PRIMARY]
GO CREATE INDEX [IX_Manager__Branch_Code] ON [dbo].[Manager]([Branch_Code]) ON [PRIMARY]
GO CREATE INDEX [IX_Manager__Position_Id] ON [dbo].[Manager]([Position_Id]) ON [PRIMARY]
GO CREATE INDEX [IX_Manager__IsWork] ON [dbo].[Manager]([IsWork]) ON [PRIMARY]
GO CREATE INDEX [IX_Manager__IsEnable] ON [dbo].[Manager]([IsEnable]) ON [PRIMARY]
GO CREATE INDEX [IX_Manager__CName] ON [dbo].[Manager]([CName]) ON [PRIMARY]
GO CREATE INDEX [IX_Manager__EName] ON [dbo].[Manager]([EName]) ON [PRIMARY]
GO CREATE INDEX [IX_Manager__Sex] ON [dbo].[Manager]([Sex]) ON [PRIMARY]
GO exec sp_addextendedproperty N'MS_Description', N'主键Id', N'user', N'dbo', N'table', N'Manager', N'column', N'Id'
GO exec sp_addextendedproperty N'MS_Description', N'登陆账号', N'user', N'dbo', N'table', N'Manager', N'column', N'LoginName'
GO exec sp_addextendedproperty N'MS_Description', N'登陆密码', N'user', N'dbo', N'table', N'Manager', N'column', N'LoginPass'
GO exec sp_addextendedproperty N'MS_Description', N'最后登陆时间', N'user', N'dbo', N'table', N'Manager', N'column', N'LoginTime'
GO exec sp_addextendedproperty N'MS_Description', N'最后登陆IP', N'user', N'dbo', N'table', N'Manager', N'column', N'LoginIp'
GO exec sp_addextendedproperty N'MS_Description', N'登陆次数', N'user', N'dbo', N'table', N'Manager', N'column', N'LoginCount'
GO exec sp_addextendedproperty N'MS_Description', N'注册时间', N'user', N'dbo', N'table', N'Manager', N'column', N'CreateTime'
GO exec sp_addextendedproperty N'MS_Description', N'资料最后修改日期', N'user', N'dbo', N'table', N'Manager', N'column', N'UpdateTime'
GO exec sp_addextendedproperty N'MS_Description', N'是否允许同一帐号多人使用,0=只能单个在线,1=可以多人同时在线', N'user', N'dbo', N'table', N'Manager', N'column', N'IsMultiUser'
GO exec sp_addextendedproperty N'MS_Description', N'所属部门ID', N'user', N'dbo', N'table', N'Manager', N'column', N'Branch_Id'
GO exec sp_addextendedproperty N'MS_Description', N'所属部门编号,用户只能正式归属于一个部门', N'user', N'dbo', N'table', N'Manager', N'column', N'Branch_Code'
GO exec sp_addextendedproperty N'MS_Description', N'部门名称', N'user', N'dbo', N'table', N'Manager', N'column', N'Branch_Name'
GO exec sp_addextendedproperty N'MS_Description', N'用户职位ID', N'user', N'dbo', N'table', N'Manager', N'column', N'Position_Id'
GO exec sp_addextendedproperty N'MS_Description', N'职位名称', N'user', N'dbo', N'table', N'Manager', N'column', N'Position_Name'
GO exec sp_addextendedproperty N'MS_Description', N'0=离职,1=就职', N'user', N'dbo', N'table', N'Manager', N'column', N'IsWork'
GO exec sp_addextendedproperty N'MS_Description', N'账号是否启用,1=true(启用),0=false(禁用)', N'user', N'dbo', N'table', N'Manager', N'column', N'IsEnable'
GO exec sp_addextendedproperty N'MS_Description', N'用户中文名称', N'user', N'dbo', N'table', N'Manager', N'column', N'CName'
GO exec sp_addextendedproperty N'MS_Description', N'用户英文名称', N'user', N'dbo', N'table', N'Manager', N'column', N'EName'
GO exec sp_addextendedproperty N'MS_Description', N'头像图片路径', N'user', N'dbo', N'table', N'Manager', N'column', N'PhotoImg'
GO exec sp_addextendedproperty N'MS_Description', N'性别(0=未知,1=男,2=女)', N'user', N'dbo', N'table', N'Manager', N'column', N'Sex'
GO exec sp_addextendedproperty N'MS_Description', N'出生日期', N'user', N'dbo', N'table', N'Manager', N'column', N'Birthday'
GO exec sp_addextendedproperty N'MS_Description', N'籍贯', N'user', N'dbo', N'table', N'Manager', N'column', N'NativePlace'
GO exec sp_addextendedproperty N'MS_Description', N'民族', N'user', N'dbo', N'table', N'Manager', N'column', N'NationalName'
GO exec sp_addextendedproperty N'MS_Description', N'个人--学历', N'user', N'dbo', N'table', N'Manager', N'column', N'Record'
GO exec sp_addextendedproperty N'MS_Description', N'毕业学校', N'user', N'dbo', N'table', N'Manager', N'column', N'GraduateCollege'
GO exec sp_addextendedproperty N'MS_Description', N'毕业专业', N'user', N'dbo', N'table', N'Manager', N'column', N'GraduateSpecialty'
GO exec sp_addextendedproperty N'MS_Description', N'个人--联系电话', N'user', N'dbo', N'table', N'Manager', N'column', N'Tel'
GO exec sp_addextendedproperty N'MS_Description', N'个人--移动电话', N'user', N'dbo', N'table', N'Manager', N'column', N'Mobile'
GO exec sp_addextendedproperty N'MS_Description', N'个人--联系邮箱', N'user', N'dbo', N'table', N'Manager', N'column', N'Email'
GO exec sp_addextendedproperty N'MS_Description', N'个人--QQ', N'user', N'dbo', N'table', N'Manager', N'column', N'Qq'
GO exec sp_addextendedproperty N'MS_Description', N'个人--Msn', N'user', N'dbo', N'table', N'Manager', N'column', N'Msn'
GO exec sp_addextendedproperty N'MS_Description', N'个人--通讯地址', N'user', N'dbo', N'table', N'Manager', N'column', N'Address'
GO exec sp_addextendedproperty N'MS_Description', N'备注', N'user', N'dbo', N'table', N'Manager', N'column', N'Content'
GO exec sp_addextendedproperty N'MS_Description', N'修改人员id', N'user', N'dbo', N'table', N'Manager', N'column', N'Manager_Id'
GO exec sp_addextendedproperty N'MS_Description', N'修改人中文名称', N'user', N'dbo', N'table', N'Manager', N'column', N'Manager_CName'
GO /****** Object: Table [dbo].[OnlineUsers] Script Date: 2014/6/4 22:27:52 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[OnlineUsers]') and OBJECTPROPERTY(id, N'IsUserTable') = )
drop table [dbo].[OnlineUsers]
GO /****** Object: Table [dbo].[OnlineUsers] Script Date: 2014/6/4 22:27:52 ******/
CREATE TABLE [dbo].[OnlineUsers] (
[Id] [int] IDENTITY (, ) NOT NULL,
[UserHashKey] [nvarchar] () NOT NULL,
[Manager_Id] [int] NOT NULL,
[Manager_LoginName] [nvarchar] () NOT NULL,
[Manager_LoginPass] [nvarchar] () NOT NULL,
[Manager_CName] [nvarchar] () NOT NULL,
[LoginTime] [datetime] NOT NULL,
[LoginIp] [nvarchar] () NOT NULL,
[UserKey] [nvarchar] () NOT NULL,
[Md5] [nvarchar] () NOT NULL,
[UpdateTime] [datetime] NOT NULL,
[Sex] [nvarchar] () NOT NULL,
[Branch_Id] [int] NOT NULL,
[Branch_Code] [nvarchar] () NOT NULL,
[Branch_Name] [nvarchar] () NOT NULL,
[Position_Id] [nvarchar] () NOT NULL,
[Position_Name] [nvarchar] () NOT NULL,
[CurrentPage] [nvarchar] () NOT NULL,
[CurrentPageTitle] [nvarchar] () NOT NULL,
[SessionId] [nvarchar] () NOT NULL,
[UserAgent] [nvarchar] () NOT NULL,
[OperatingSystem] [nvarchar] () NOT NULL,
[TerminalType] [int] NOT NULL,
[BrowserName] [nvarchar] () NOT NULL,
[BrowserVersion] [nvarchar] () NOT NULL
) ON [PRIMARY]
GO ALTER TABLE [dbo].[OnlineUsers] WITH NOCHECK ADD
CONSTRAINT [PK_OnlineUsers] PRIMARY KEY CLUSTERED
(
[Id]
) ON [PRIMARY]
GO ALTER TABLE [dbo].[OnlineUsers] ADD
CONSTRAINT [DF_OnlineUsers_UserHashKey] DEFAULT ('') FOR [UserHashKey],
CONSTRAINT [DF_OnlineUsers_Manager_Id] DEFAULT () FOR [Manager_Id],
CONSTRAINT [DF_OnlineUsers_Manager_LoginName] DEFAULT ('') FOR [Manager_LoginName],
CONSTRAINT [DF_OnlineUsers_Manager_LoginPass] DEFAULT ('') FOR [Manager_LoginPass],
CONSTRAINT [DF_OnlineUsers_Manager_CName] DEFAULT ('') FOR [Manager_CName],
CONSTRAINT [DF_OnlineUsers_LoginTime] DEFAULT (getdate()) FOR [LoginTime],
CONSTRAINT [DF_OnlineUsers_LoginIp] DEFAULT ('') FOR [LoginIp],
CONSTRAINT [DF_OnlineUsers_UserKey] DEFAULT ('') FOR [UserKey],
CONSTRAINT [DF_OnlineUsers_Md5] DEFAULT ('') FOR [Md5],
CONSTRAINT [DF_OnlineUsers_UpdateTime] DEFAULT (getdate()) FOR [UpdateTime],
CONSTRAINT [DF_OnlineUsers_Sex] DEFAULT ('') FOR [Sex],
CONSTRAINT [DF_OnlineUsers_Branch_Id] DEFAULT () FOR [Branch_Id],
CONSTRAINT [DF_OnlineUsers_Branch_Code] DEFAULT ('') FOR [Branch_Code],
CONSTRAINT [DF_OnlineUsers_Branch_Name] DEFAULT ('') FOR [Branch_Name],
CONSTRAINT [DF_OnlineUsers_Position_Id] DEFAULT ('') FOR [Position_Id],
CONSTRAINT [DF_OnlineUsers_Position_Name] DEFAULT ('') FOR [Position_Name],
CONSTRAINT [DF_OnlineUsers_CurrentPage] DEFAULT ('') FOR [CurrentPage],
CONSTRAINT [DF_OnlineUsers_CurrentPageTitle] DEFAULT ('') FOR [CurrentPageTitle],
CONSTRAINT [DF_OnlineUsers_SessionId] DEFAULT ('') FOR [SessionId],
CONSTRAINT [DF_OnlineUsers_UserAgent] DEFAULT ('') FOR [UserAgent],
CONSTRAINT [DF_OnlineUsers_OperatingSystem] DEFAULT ('') FOR [OperatingSystem],
CONSTRAINT [DF_OnlineUsers_TerminalType] DEFAULT () FOR [TerminalType],
CONSTRAINT [DF_OnlineUsers_BrowserName] DEFAULT ('') FOR [BrowserName],
CONSTRAINT [DF_OnlineUsers_BrowserVersion] DEFAULT ('') FOR [BrowserVersion]
GO CREATE INDEX [IX_OnlineUsers__Manager_Id] ON [dbo].[OnlineUsers]([Manager_Id]) ON [PRIMARY]
GO CREATE INDEX [IX_OnlineUsers__Manager_LoginName] ON [dbo].[OnlineUsers]([Manager_LoginName]) ON [PRIMARY]
GO CREATE INDEX [IX_OnlineUsers__Manager_CName] ON [dbo].[OnlineUsers]([Manager_CName]) ON [PRIMARY]
GO CREATE INDEX [IX_OnlineUsers__LoginTime] ON [dbo].[OnlineUsers]([LoginTime]) ON [PRIMARY]
GO CREATE INDEX [IX_OnlineUsers__UpdateTime] ON [dbo].[OnlineUsers]([UpdateTime]) ON [PRIMARY]
GO CREATE INDEX [IX_OnlineUsers__Branch_Id] ON [dbo].[OnlineUsers]([Branch_Id]) ON [PRIMARY]
GO CREATE INDEX [IX_OnlineUsers__Branch_Code] ON [dbo].[OnlineUsers]([Branch_Code]) ON [PRIMARY]
GO CREATE INDEX [IX_OnlineUsers__Position_Id] ON [dbo].[OnlineUsers]([Position_Id]) ON [PRIMARY]
GO exec sp_addextendedproperty N'MS_Description', N'主键Id', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'Id'
GO exec sp_addextendedproperty N'MS_Description', N'在线用户列表中的HashTable Key值', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'UserHashKey'
GO exec sp_addextendedproperty N'MS_Description', N'用户Id', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'Manager_Id'
GO exec sp_addextendedproperty N'MS_Description', N'登陆账号', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'Manager_LoginName'
GO exec sp_addextendedproperty N'MS_Description', N'登陆密码', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'Manager_LoginPass'
GO exec sp_addextendedproperty N'MS_Description', N'用户中文名称', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'Manager_CName'
GO exec sp_addextendedproperty N'MS_Description', N'登陆时间', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'LoginTime'
GO exec sp_addextendedproperty N'MS_Description', N'登陆IP', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'LoginIp'
GO exec sp_addextendedproperty N'MS_Description', N'用户密钥', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'UserKey'
GO exec sp_addextendedproperty N'MS_Description', N'Md5(密钥+登陆帐号+密码+IP+密钥.Substring(6,8))', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'Md5'
GO exec sp_addextendedproperty N'MS_Description', N'最后在线时间', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'UpdateTime'
GO exec sp_addextendedproperty N'MS_Description', N'性别(0=未知,1=男,2=女)', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'Sex'
GO exec sp_addextendedproperty N'MS_Description', N'所属部门ID', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'Branch_Id'
GO exec sp_addextendedproperty N'MS_Description', N'所属部门编号,用户只能正式归属于一个部门', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'Branch_Code'
GO exec sp_addextendedproperty N'MS_Description', N'部门名称', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'Branch_Name'
GO exec sp_addextendedproperty N'MS_Description', N'用户职位ID', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'Position_Id'
GO exec sp_addextendedproperty N'MS_Description', N'职位名称', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'Position_Name'
GO exec sp_addextendedproperty N'MS_Description', N'用户当前所在页面Url', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'CurrentPage'
GO exec sp_addextendedproperty N'MS_Description', N'用户当前所在页面名称', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'CurrentPageTitle'
GO exec sp_addextendedproperty N'MS_Description', N'用户SessionId', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'SessionId'
GO exec sp_addextendedproperty N'MS_Description', N'客户端UA', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'UserAgent'
GO exec sp_addextendedproperty N'MS_Description', N'操作系统', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'OperatingSystem'
GO exec sp_addextendedproperty N'MS_Description', N'终端类型(0=非移动设备,1=移动设备)', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'TerminalType'
GO exec sp_addextendedproperty N'MS_Description', N'浏览器名称', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'BrowserName'
GO exec sp_addextendedproperty N'MS_Description', N'浏览器的版本', N'user', N'dbo', N'table', N'OnlineUsers', N'column', N'BrowserVersion'
GO

  7、添加后端相关表默认记录

 --添加部门记录
INSERT INTO Branch (Code, Name, Notes, ParentId, Sort, Depth, Manager_Id, Manager_CName)
VALUES ('', 'XX公司', '', 0, 1, 0, 1, 'admin')
GO --添加职位记录
INSERT INTO Position (Name, Branch_Id, Branch_Code, Branch_Name, PagePower, ControlPower, IsSetBranchPower, SetBranchCode, Manager_Id, Manager_CName)
VALUES ('软件开发工程师', 1, '', 'XX公司', '', '', 1, '', 1, 'admin')
GO --添加管理员
INSERT INTO Manager (LoginName, LoginPass, LoginIp, LoginCount, Branch_Id, Branch_Code, Branch_Name, Position_Id, Position_Name, IsWork, IsEnable, CName, EName, Sex, Manager_Id, Manager_CName)
VALUES ('admin', 'c3284d0f94606de1fd2af172aba15bf3', '127.0.0.1', 0, 1, '', 'XX公司', '', '软件开发工程师', 1, 1, 'admin', 'admin', '男', 1, 'admin')
GO

  8、运行T4模板,为新加的表与修改的字段生成DAL层与BLL层代码

  

  9、登陆页cs文件代码(根据上面的流程图+代码中详细注释,大家应该很容易看明白)

 using System;
using System.Collections;
using System.Web;
using System.Web.Caching;
using DotNet.Utilities;
using Solution.DataAccess.DataModel;
using Solution.Logic.Managers; namespace Solution.Web.Managers.WebManage
{
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ //进入登陆页面时判断是否是后台直接点击退出的,是的话加退出记录
LoginLogBll.GetInstence().UserExit(); #region 初始化用户Session变量
//在线用户生成的session标识
Session["UserHashKey"] = null;
//当前用户可访问的页面
Session["PagePower"] = null;
//当前用户页面中可使用的按钮控件
Session["ControlPower"] = null;
#endregion
}
} /// <summary>登录</summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void BtnLogin_Click(object sender, EventArgs e)
{
var ip = IpHelper.GetUserIp(); #region 获取用户输入的参数,并进行数据初步处理
//获取用户名,并进行危险字符过滤
var username = StringHelper.Left(txtusername.Text, );
//获取用户密码
var userpass = txtpass.Text;
//获取验证码
var strCode = StringHelper.Left(txtcode.Text, );
#endregion #region 初步验证
//开发测试使用,不用每次都输入帐号与密码
//username = "admin";
//userpass = "admin";
//strCode = "12345"; //用户名验证
if (string.IsNullOrEmpty(username.Trim()))
{
txtusername.Focus();
JsHelper.Alert("用户名不能为空,请仔细检查您输入的用户名!");
return;
}
//密码验证
if (string.IsNullOrEmpty(userpass.Trim()))
{
txtpass.Focus();
JsHelper.Alert("密码不能为空,请仔细检查您输入的密码!");
return;
} //验证码验证
if (string.IsNullOrEmpty(strCode))
{
txtcode.Focus();
JsHelper.Alert("验证码不能为空!");
return;
}
//判断验证码是否正确
if (Session["vcode"] == null || !Session["vcode"].ToString().Equals(strCode, StringComparison.InvariantCultureIgnoreCase))
{
SessionHelper.RemoveSession("vcode");
txtpass.Focus();
JsHelper.Alert("验证码错误!");
return;
}
else
{
//验证码正确,删除验证码Session
SessionHelper.RemoveSession("vcode");
}
#endregion #region 数据库验证 //通过用户给的用户名获取相关实体类
var userinfo = Manager.SingleOrDefault(x => x.LoginName == username); //判断用户是否存在
if (userinfo == null)
{
LoginLogBll.GetInstence().Save(, "账号【" + username + "】不存在,登录失败!");
txtusername.Focus();
JsHelper.Alert("用户名不存在,请仔细检查您输入的用户名!");
return;
} //密码不匹配
if (!userinfo.LoginPass.Equals(Encrypt.Md5(Encrypt.Md5(userpass))))
{
LoginLogBll.GetInstence().Save(userinfo.Id, "账号【" + userinfo.LoginName + "】的用户【" + userinfo.CName + "】登录失败!登录密码错误。");
txtpass.Focus();
JsHelper.Alert("您输入的用户密码错误!");
return;
} if (userinfo.IsWork == )
{
//添加用户登陆日志
LoginLogBll.GetInstence().Save(userinfo.Id, "离职用户登录失败!用户【" + userinfo.CName + "】试图登录系统");
JsHelper.Alert("您已经没有权限登录本系统!");
return;
} //判断当前账号是否被启用
if (userinfo.IsEnable == )
{
//添加登录日志记录
LoginLogBll.GetInstence().Save(userinfo.Id, "账号【" + userinfo.LoginName + "】的用户【" + userinfo.CName + "】登录失败!用户账号被禁用。"); JsHelper.Alert("当前账号未被启用,请联系管理人员激活!");
return;
} #endregion #region 存储在线用户资料 #region 获取用户操作权限 if (string.IsNullOrEmpty(userinfo.Position_Id))
{
Session["PagePower"] = "";
Session["ControlPower"] = ""; LoginLogBll.GetInstence().Save(, "账号【" + username + "】未绑定职位,请管理员进行配置!");
JsHelper.Alert("您的账号未绑定职位,请与管理员联系!");
return;
}
else
{
//获取用户权限并存储到用户Session里
PositionBll.GetInstence().SetUserPower(userinfo.Position_Id);
} #endregion #region 当前用户在线信息
//当前时间
var localTime = DateTime.Now.ToLocalTime();
//创建客户端信息获取实体
var clientHelper = new ClientHelper(Request); //创建在线用户实体
var onlineUser = new Solution.DataAccess.Model.OnlineUsers();
//当前用户的Id编号
onlineUser.Manager_Id = userinfo.Id;
onlineUser.Manager_LoginName = userinfo.LoginName;
onlineUser.Manager_LoginPass = userinfo.LoginPass;
onlineUser.Manager_CName = userinfo.CName;
onlineUser.LoginTime = localTime;
onlineUser.LoginIp = ip;
//生成密钥
onlineUser.UserKey = RandomHelper.GetRndNum(, true);
//Md5(密钥+登陆帐号+密码+IP+密钥.Substring(6,8))
onlineUser.Md5 =
Encrypt.Md5(onlineUser.UserKey + onlineUser.Manager_LoginName + onlineUser.Manager_LoginPass +
onlineUser.LoginIp + onlineUser.UserKey.Substring(, ));
onlineUser.UpdateTime = localTime;
onlineUser.Sex = userinfo.Sex;
onlineUser.Branch_Id = userinfo.Branch_Id;
onlineUser.Branch_Code = userinfo.Branch_Code;
onlineUser.Branch_Name = userinfo.Branch_Name;
onlineUser.Position_Id = userinfo.Position_Id;
onlineUser.Position_Name = userinfo.Position_Name;
onlineUser.CurrentPage = "";
onlineUser.CurrentPageTitle = "";
//SessionId
onlineUser.SessionId = Session.SessionID;
onlineUser.UserAgent = StringHelper.FilterSql(HttpContext.Current.Request.Headers["User-Agent"] + "");
onlineUser.OperatingSystem = clientHelper.GetSystem();
onlineUser.TerminalType = clientHelper.IsMobileDevice(onlineUser.UserAgent) ? : ;
onlineUser.BrowserName = clientHelper.GetBrowserName();
onlineUser.BrowserVersion = clientHelper.GetBrowserVersion(); #endregion #region 记录当前用户UserId
//定义HashTable表里Key的名称UserId
string userHashKey = "";
//判断当前用户帐户是否支持同一帐号在不同地方登陆功能,取得用户在HashTable表里Key的名称
//不支持则
if (userinfo.IsMultiUser == )
{
userHashKey = userinfo.Id + "";
}
//支持则
else
{
userHashKey = userinfo.Id + "_" + onlineUser.SessionId;
}
//记录用户的HashTable Key
onlineUser.UserHashKey = userHashKey;
Session["UserHashKey"] = userHashKey;
#endregion #region 将在线用户信息存入全局变量中
//运行在线数据加载函数,如果缓存不存在,则尝试加载数据库中的在线表记录到缓存中
//——主要用于IIS缓存被应用程序池或其他原因回收后,对在线数据进行重新加载,而不会使所有用户都被迫退出系统
OnlineUsersBll.GetInstence().Load(); //判断缓存中["OnlineUsers"]是否存在,不存在则直接将在线实体添加到缓存中
if (CacheHelper.GetCache("OnlineUsers") == null)
{
//将当前用户信息添加到Hashtable中
var hashtable = new Hashtable();
hashtable.Add(userHashKey, onlineUser);
//将在线列表(Hashtable)添中进系统缓存中
CacheHelper.SetCache("OnlineUsers", hashtable);
}
//存在则将它取出HashTable并进行处理
else
{
//直接从缓存中读取在线列表数据
var hashtable = (Hashtable)CacheHelper.GetCache("OnlineUsers"); //判断当前用户是否存在在线表中,不存在则直接将当前用户的实体对象存储进HashTable
if (hashtable[userHashKey] == null || hashtable.Count == )
{
hashtable.Add(userHashKey, onlineUser);
}
//存在则
else
{
//添加用户下线记录
LoginLogBll.GetInstence().Save(userHashKey, "用户【{0}】的账号已经在另一处登录,本次登陆下线!在线时间【{1}】"); //将HashTable里存储的前一登陆帐户移除
OnlineUsersBll.GetInstence().Delete(this, x => x.UserHashKey == userHashKey);
//移除缓存中的记录
hashtable.Remove(userHashKey); //将当前用户的实体对象存进在线缓存中
hashtable.Add(userHashKey, onlineUser);
}
} //将在线实体保存到数据库的在线表中
OnlineUsersBll.GetInstence().Save(this, OnlineUsersBll.GetInstence().Transform(onlineUser)); //将用户信息表添加到缓存中,并且以150秒的轮询用户在线情况
//new PageBase().OnRemovedCallback为缓存回调函数,用于缓存失效、过期、删除或回收时,所触发的回调函数,执行相应操作
//缓存Key的前面加了"OnlineUsers_"标识,主要是用于清空缓存时区分用户缓存和其他系统缓存,不会将在线用户都清除下线
HttpRuntime.Cache.Insert("OnlineUsers_" + userHashKey, userHashKey, null, DateTime.MaxValue, TimeSpan.FromSeconds(), CacheItemPriority.Default, new CacheItemRemovedCallback(OnRemovedCallback)); //更新在线列表数据,将不在线人员删除
OnlineUsersBll.GetInstence().UpdateUserOnlineCount(); #endregion #endregion #region 更新用户登陆信息 userinfo.LoginIp = ip;
userinfo.LoginCount = userinfo.LoginCount++;
userinfo.LoginTime = localTime; ManagerBll.GetInstence().Save(this, userinfo, string.Format("用户【{0}】登陆成功,更新登陆信息", userinfo.CName)); #endregion #region 添加用户登录成功日志
LoginLogBll.GetInstence().Save(userHashKey, string.Format("账号【{0}】的用户【{1}】登录成功", userinfo.LoginName, userinfo.CName));
#endregion #region 写Cookies
//写入用户的HashTable Key
CookieHelper.SetCookie(OnlineUsersTable.UserHashKey, userHashKey);
//写入加密值
CookieHelper.SetCookie(OnlineUsersTable.Md5, onlineUser.Md5);
#endregion //跳转进入主页面
Response.Redirect("MainPage.aspx");
} #region 缓存回调函数
/// <summary>
/// 缓存回调函数,用于缓存失效、过期、删除或回收时,所触发的回调函数,执行相应操作
/// </summary>
/// <param name="key">缓存Key</param>
/// <param name="value">缓存值</param>
/// <param name="reason">触发的原因</param>
public void OnRemovedCallback(string key, object value, CacheItemRemovedReason reason)
{
if (key == null || value == null)
return; //更新在线列表数据,将不在线人员删除
OnlineUsersBll.GetInstence().UpdateUserOnlineCount(); //switch (reason)
//{
// //相关联的缓存已经失效
// case CacheItemRemovedReason.DependencyChanged:
// break; // //当前用户缓存已过期
// case CacheItemRemovedReason.Expired:
// //更新在线列表数据,将不在线人员删除
// OnlineUsersBll.UpdateUserOnlineCount(); // break; // //当前用户已被删除
// case CacheItemRemovedReason.Removed:
// break; // //系统释放内存自动回收当前用户
// case CacheItemRemovedReason.Underused:
// //更新在线列表数据,将不在线人员删除
// OnlineUsersBll.UpdateUserOnlineCount(); // break; //}
}
#endregion
}
}

  后端登陆页面界面随便在网上找了个改了一下,弄得很简陋,大家如果有好的UI可以发到我邮箱,我下次更新上去O(∩_∩)O

点击下载:

由于框架不是非常成熟,很多朋友不是用来学习而是直接用到项目中,但不熟悉框架引起不少小问题,所以停止提供下载,有需要学习的可以到群共享里下,不便之处敬请谅解。

 版权声明:

  本文由AllEmpty原创并发布于博客园,欢迎转载,未经本人同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。如有问题,可以通过1654937@qq.com 联系我,非常感谢。

  发表本编内容,只要主为了和大家共同学习共同进步,有兴趣的朋友可以加加Q群:327360708 ,大家一起探讨。

  更多内容,敬请观注博客:http://www.cnblogs.com/EmptyFS/

最新文章

  1. git回滚到任意版本
  2. Elastic Image Slider 带缩略图功能的幻灯片
  3. js DOM Element属性和方法整理
  4. equals方法的小结
  5. Java 集合深入理解(15):AbstractMap
  6. Keil : Contents missmatch at:08000E84H Verify Failed!
  7. 第46条:for-each循环优先于传统的for循环
  8. 通过winForm控制webForm的上传控件file的值
  9. SSMS2008插件开发(1)--介绍
  10. C# 语言规范_版本5.0 (第18章 不安全代码)
  11. BZOJ_3316_JC loves Mkk_ 二分答案 + 单调队列
  12. autoit学习安装说明及例子
  13. Hbase的基本操作(CDH组件可用)
  14. IMPLEMENTATION - Entity Framework Anti Pattern - High Performance EF
  15. Reporting Service 2008 &ldquo;报表服务器数据库内出错。此错误可能是因连接失败、超时或数据库中磁盘空间不足而导致的&rdquo;
  16. es6冲刺01
  17. hbase源码系列(十五)终结篇&amp;Scan续集--&gt;如何查询出来下一个KeyValue
  18. centos Cannot allocate memory for the buffer pool
  19. Fiddler模拟Http请求
  20. 3星|《给你讲个笑话:我是创业公司CEO》:创业成功就是上帝掷骰子

热门文章

  1. a标签点击跳转失效--IE6、7的奇葩bug
  2. DDD CQRS架构和传统架构的优缺点比较
  3. JAVA问题集锦Ⅰ
  4. 120项改进:开源超级爬虫Hawk 2.0 重磅发布!
  5. JDK动态代理
  6. c# 字符串连接使用“+”和string.format格式化两种方式
  7. “RazorEngine.Templating.TemplateParsingException”类型的异常在 RazorEngine.NET4.0.dll 中发生,但未在用户代码中进行处理 其他信息: Expected model identifier.
  8. javascript高性能编程-算法和流程控制
  9. mysql开启慢查询日志及查询--windows
  10. MySQL:常见使用问题