第六章 用户权限管理(五) -- 用户登录管理
2012-09-19 09:13
148 查看
6.6 角色用户管理设计与实现
6.6.3 用户登录管理
用户登录管理首先由管理员为用户设置用户名和密码,如上一页的图6.17所示。
如图6.19所示,电子政务系统的工作界面由几个框架页面组成。用户在调用系统首页面Index.aspx时,如果未登录,系统将跳转到登录页面Login.aspx。用户登录后,左侧框架页面将根据登录用户的角色权限显示不同的工作菜单。
图6.19 政务系统首页
如图6.19所示,在系统主页面的左侧菜单,用户可以随时点击“修改密码”菜单进行密码修改;可以点击顶部框架页面的退出按钮,退出登录;退出登录后的顶部框架页面将显示如图中箭头所指的登录控件,用户可以重新登录。
与用户登录管理相关的程序代码如下:
1、Index.aspx文件代码:
<%@ Page language="c#" Codebehind="Index.aspx.cs"
Inherits="workflow.Index" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<frameset rows="100,*,50" frameborder="NO" border="0" framespacing="0">
<frame src="Top.aspx" name="topFrame" scrolling="NO" noresize>
<frameset cols="190,*" frameborder="NO" border="0" framespacing="0">
<frame src="Left.aspx" name="leftFrame" scrolling="YES" noresize>
<frame src="chaoqiliuchengliebiao.htm" name="mainFrame">
</frameset>
<frame src="bottom.htm" name="bottomFrame" scrolling="NO" noresize>
</frameset>
<noframes>
<body>
</body>
</noframes>
</html>
Index.aspx.cs文件代码:
....
namespace workflow
{
public class Index : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
if(! IsPostBack)
{
if(Session["userid"] == null)
Response.Redirect("./Login.aspx");
}
}
}
}
2、Left.aspx文件代码:
......
<html>
<body>
<form id="Form1" method="post" runat="server">
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td class="navbg" vAlign="top" align="center" style="HEIGHT: 31px"><br>
<% if(officeresourcetypeds != null)
{
for(int i=0;i<officeresourcetypeds.Tables[0].Rows.Count;i++)
{
%>
<table width="96%" border="0" cellpadding="0" cellspacing="0" class='boxborder'>
<tr><td><DIV class="parent">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td class="boxtitle"><a href="#" onclick="">
<%=officeresourcetypeds.Tables[0].Rows[i]["CategoryName"].ToString()%></a>
</td>
</tr>
</table></DIV>
<table style='DISPLAY:block' width="100%" border="0" cellspacing="0"
cellpadding="0">
<tr>
<td class="boxcontent"><DIV class="child">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<% linkresourceds=basemanager.GetOfficeLinkResource(rolesds,
officeresourcetypeds.Tables[0].Rows[i]["CateGoryID"].ToString());
if(linkresourceds != null)
{
for(int j=0;j<linkresourceds.Tables[0].Rows.Count;j++)
{
%>
<TR>
<TD align="center" width="20%" height="25"><IMG height="4"
src="images/dot.gif" width="4"></TD>
<TD width="80%">
<A href="<%=linkresourceds.Tables[0].Rows[j]["Link"]
.ToString()%>" target="mainFrame">
<%=linkresourceds.Tables[0].Rows[j]["ResourceName"].ToString()%>
</A>
</TD>
</TR>
<% }
}
%>
</table></DIV>
</td></tr>
</table>
</td></tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td height="7"></td>
</tr>
</table>
<% }
}
%>
</td></tr>
</table>
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr><td class="navbg" vAlign="top" align="center" style="HEIGHT: 31px">
<table width="96%" border="0" cellpadding="0" cellspacing="0" class='boxborder'>
<tr><td><DIV class="parent" id="KB1Parent">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr><td class="boxtitle">
<a href="#" onclick="">个人信息维护</a>
</td></tr>
</table></DIV>
<table style='DISPLAY:block' width="100%" border="0" cellspacing="0"
cellpadding="0">
<tr><td class="boxcontent"><DIV class="child" id="KB1Child">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<TR><TD align="center" width="20%" height="25">
<IMG height="4" src="images/dot.gif" width="4">
</TD>
<TD width="80%">
<A href="UpdatePassword.aspx" target="mainFrame">修改密码</A>
</TD>
</TR>
</table></DIV>
</td></tr></table>
</td></tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td height="7"></td></tr>
</table>
</td></tr>
</table>
</form>
</body>
</HTML>
Left.aspx.cs文件代码:
namespace workflow
{
public class Left : System.Web.UI.Page
{
protected DataSet rolesds=null;
protected DataSet officeresourcetypeds=null;
protected DataSet linkresourceds=null;
protected UserManagement basemanager;
private void Page_Load(object sender, System.EventArgs e)
{
if(! IsPostBack)
{
if(Session["userid"] == null)
Response.Redirect("./Message.aspx");
basemanager=new UserManagement();
rolesds=basemanager.GetRoles(Session["userid"].ToString());
if(rolesds != null)
officeresourcetypeds=basemanager.GetOfficeResourceType(rolesds);
}
}
}
}
3、Top.aspx文件代码:
....
<form id="Form1" method="post" runat="server">
<script language="javascript">
function DateDemo(){
var d, s ;
d = new Date();
s = d.getYear()+"-";
s += (d.getMonth() + 1) + "-";
s += d.getDate() ;
return(s);
}
</script>
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
......
<tr>
<td class="headerbottom" id="Header1_CellLogin" colSpan="2">
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>......
<td align="right" width="52%">
<%
if(Session["userid"]!=null)
{
%>
<font color="white">
<asp:label id="Label1" runat="server" ForeColor="White"></asp:label>
<span id="Header1_Label1">
今天是<script>document.write(DateDemo());</script>
<asp:linkbutton id="LinkButton1" runat="server">[退出]</asp:linkbutton>
</span></font>
<%
}
else
{
%>
<font color="white">用户名:</font>
<asp:TextBox id="TextBox1" runat="server" Columns="16"></asp:TextBox>
<font color="white">密码: </font>
<asp:TextBox id="TextBox2" runat="server" Columns="16"
TextMode="Password"></asp:TextBox>
<asp:LinkButton id="LinkButton2" runat="server">[登录]</asp:LinkButton>
<asp:Label id="Label2" runat="server" ForeColor="Red"></asp:Label>
<%
}
%>
</td></tr>
</table>
</td></tr>
</table>
......
</form>
Top.aspx.cs文件代码:
namespace workflow
{
public class Top : System.Web.UI.Page
{
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.LinkButton LinkButton2;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label1;
private void Page_Load(object sender, System.EventArgs e)
{
if(! IsPostBack)
{
if(Session["userid"]==null)
Label1.Text="您还没有登录";
else
{
string strSql="select EmployeeName from Employees where EmployeeID=(select
EmployeeID from Users where UserID="+Session["userid"].ToString ()+")";
DataSet ds=new DataAccess.Base().SQLExeDataSet(strSql);
Label1.Text="您好,"+ds.Tables[0].Rows[0]["EmployeeName"].ToString ();
}
}
Label2.Text="";
}
//退出按钮
private void LinkButton1_Click(object sender, System.EventArgs e)
{
Session["userid"]=null;
Response.Write(" <script>window.parent.frames['mainFrame'].location.href
='Message.aspx';</script> ");
}
//登录按钮
private void LinkButton2_Click(object sender, System.EventArgs e)
{
string username=TextBox1.Text.Trim();
string password=TextBox2.Text.Trim();
UserManagement management=new UserManagement();
string userid=management.UserAuthentication(username,password);
if(userid == null)
{
Label2.Text="用户名或密码错误!";
return;
}
Session["userid"]=userid;
Response.Write(" <script>window.parent.location.href='Index.aspx';</script> ");
}
}
}
6.6.3 用户登录管理
用户登录管理首先由管理员为用户设置用户名和密码,如上一页的图6.17所示。
如图6.19所示,电子政务系统的工作界面由几个框架页面组成。用户在调用系统首页面Index.aspx时,如果未登录,系统将跳转到登录页面Login.aspx。用户登录后,左侧框架页面将根据登录用户的角色权限显示不同的工作菜单。
图6.19 政务系统首页
如图6.19所示,在系统主页面的左侧菜单,用户可以随时点击“修改密码”菜单进行密码修改;可以点击顶部框架页面的退出按钮,退出登录;退出登录后的顶部框架页面将显示如图中箭头所指的登录控件,用户可以重新登录。
与用户登录管理相关的程序代码如下:
1、Index.aspx文件代码:
<%@ Page language="c#" Codebehind="Index.aspx.cs"
Inherits="workflow.Index" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<frameset rows="100,*,50" frameborder="NO" border="0" framespacing="0">
<frame src="Top.aspx" name="topFrame" scrolling="NO" noresize>
<frameset cols="190,*" frameborder="NO" border="0" framespacing="0">
<frame src="Left.aspx" name="leftFrame" scrolling="YES" noresize>
<frame src="chaoqiliuchengliebiao.htm" name="mainFrame">
</frameset>
<frame src="bottom.htm" name="bottomFrame" scrolling="NO" noresize>
</frameset>
<noframes>
<body>
</body>
</noframes>
</html>
Index.aspx.cs文件代码:
....
namespace workflow
{
public class Index : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
if(! IsPostBack)
{
if(Session["userid"] == null)
Response.Redirect("./Login.aspx");
}
}
}
}
2、Left.aspx文件代码:
......
<html>
<body>
<form id="Form1" method="post" runat="server">
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td class="navbg" vAlign="top" align="center" style="HEIGHT: 31px"><br>
<% if(officeresourcetypeds != null)
{
for(int i=0;i<officeresourcetypeds.Tables[0].Rows.Count;i++)
{
%>
<table width="96%" border="0" cellpadding="0" cellspacing="0" class='boxborder'>
<tr><td><DIV class="parent">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td class="boxtitle"><a href="#" onclick="">
<%=officeresourcetypeds.Tables[0].Rows[i]["CategoryName"].ToString()%></a>
</td>
</tr>
</table></DIV>
<table style='DISPLAY:block' width="100%" border="0" cellspacing="0"
cellpadding="0">
<tr>
<td class="boxcontent"><DIV class="child">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<% linkresourceds=basemanager.GetOfficeLinkResource(rolesds,
officeresourcetypeds.Tables[0].Rows[i]["CateGoryID"].ToString());
if(linkresourceds != null)
{
for(int j=0;j<linkresourceds.Tables[0].Rows.Count;j++)
{
%>
<TR>
<TD align="center" width="20%" height="25"><IMG height="4"
src="images/dot.gif" width="4"></TD>
<TD width="80%">
<A href="<%=linkresourceds.Tables[0].Rows[j]["Link"]
.ToString()%>" target="mainFrame">
<%=linkresourceds.Tables[0].Rows[j]["ResourceName"].ToString()%>
</A>
</TD>
</TR>
<% }
}
%>
</table></DIV>
</td></tr>
</table>
</td></tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td height="7"></td>
</tr>
</table>
<% }
}
%>
</td></tr>
</table>
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr><td class="navbg" vAlign="top" align="center" style="HEIGHT: 31px">
<table width="96%" border="0" cellpadding="0" cellspacing="0" class='boxborder'>
<tr><td><DIV class="parent" id="KB1Parent">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr><td class="boxtitle">
<a href="#" onclick="">个人信息维护</a>
</td></tr>
</table></DIV>
<table style='DISPLAY:block' width="100%" border="0" cellspacing="0"
cellpadding="0">
<tr><td class="boxcontent"><DIV class="child" id="KB1Child">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<TR><TD align="center" width="20%" height="25">
<IMG height="4" src="images/dot.gif" width="4">
</TD>
<TD width="80%">
<A href="UpdatePassword.aspx" target="mainFrame">修改密码</A>
</TD>
</TR>
</table></DIV>
</td></tr></table>
</td></tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td height="7"></td></tr>
</table>
</td></tr>
</table>
</form>
</body>
</HTML>
Left.aspx.cs文件代码:
namespace workflow
{
public class Left : System.Web.UI.Page
{
protected DataSet rolesds=null;
protected DataSet officeresourcetypeds=null;
protected DataSet linkresourceds=null;
protected UserManagement basemanager;
private void Page_Load(object sender, System.EventArgs e)
{
if(! IsPostBack)
{
if(Session["userid"] == null)
Response.Redirect("./Message.aspx");
basemanager=new UserManagement();
rolesds=basemanager.GetRoles(Session["userid"].ToString());
if(rolesds != null)
officeresourcetypeds=basemanager.GetOfficeResourceType(rolesds);
}
}
}
}
3、Top.aspx文件代码:
....
<form id="Form1" method="post" runat="server">
<script language="javascript">
function DateDemo(){
var d, s ;
d = new Date();
s = d.getYear()+"-";
s += (d.getMonth() + 1) + "-";
s += d.getDate() ;
return(s);
}
</script>
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
......
<tr>
<td class="headerbottom" id="Header1_CellLogin" colSpan="2">
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>......
<td align="right" width="52%">
<%
if(Session["userid"]!=null)
{
%>
<font color="white">
<asp:label id="Label1" runat="server" ForeColor="White"></asp:label>
<span id="Header1_Label1">
今天是<script>document.write(DateDemo());</script>
<asp:linkbutton id="LinkButton1" runat="server">[退出]</asp:linkbutton>
</span></font>
<%
}
else
{
%>
<font color="white">用户名:</font>
<asp:TextBox id="TextBox1" runat="server" Columns="16"></asp:TextBox>
<font color="white">密码: </font>
<asp:TextBox id="TextBox2" runat="server" Columns="16"
TextMode="Password"></asp:TextBox>
<asp:LinkButton id="LinkButton2" runat="server">[登录]</asp:LinkButton>
<asp:Label id="Label2" runat="server" ForeColor="Red"></asp:Label>
<%
}
%>
</td></tr>
</table>
</td></tr>
</table>
......
</form>
Top.aspx.cs文件代码:
namespace workflow
{
public class Top : System.Web.UI.Page
{
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.LinkButton LinkButton2;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label1;
private void Page_Load(object sender, System.EventArgs e)
{
if(! IsPostBack)
{
if(Session["userid"]==null)
Label1.Text="您还没有登录";
else
{
string strSql="select EmployeeName from Employees where EmployeeID=(select
EmployeeID from Users where UserID="+Session["userid"].ToString ()+")";
DataSet ds=new DataAccess.Base().SQLExeDataSet(strSql);
Label1.Text="您好,"+ds.Tables[0].Rows[0]["EmployeeName"].ToString ();
}
}
Label2.Text="";
}
//退出按钮
private void LinkButton1_Click(object sender, System.EventArgs e)
{
Session["userid"]=null;
Response.Write(" <script>window.parent.frames['mainFrame'].location.href
='Message.aspx';</script> ");
}
//登录按钮
private void LinkButton2_Click(object sender, System.EventArgs e)
{
string username=TextBox1.Text.Trim();
string password=TextBox2.Text.Trim();
UserManagement management=new UserManagement();
string userid=management.UserAuthentication(username,password);
if(userid == null)
{
Label2.Text="用户名或密码错误!";
return;
}
Session["userid"]=userid;
Response.Write(" <script>window.parent.location.href='Index.aspx';</script> ");
}
}
}
相关文章推荐
- 第六章 电子政务系统的用户权限管理 -- RBAC(四)
- Oracle用户,权限,角色以及登录管理 scoot 授权
- vsftp 配置具有匿名登录也有系统用户登录,系统用户有管理权限,匿名只有下载权限。
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(19)-权限管理系统-用户登录
- tp5的RBAC插件及其使用很方便的管理用户登录及操作权限
- asp.net2.0简单用户权限管理、站点登录、导航与权限管理
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(19)-权限管理系统-用户登录
- 用户登录权限管理LDAP两种配置参考文档(spring-security和shiro)
- ASP.NET MVC+EF框架+EasyUI实现权限管理系列(12)-实现用户异步登录和T4模板
- 第六章 电子政务系统的用户权限管理 -- RBAC(一)
- 第六章 用户权限管理(六) -- C#读写数据库Image字段
- dsicuz 插件开发 判断用户是否登录/判断用户管理权限
- ylmf3.0 分配修改登录root用户管理权限的方法
- 第六章 用户权限管理(七) -- C#读写数据库Image字段
- 第六章 用户权限管理(二)- DataGrid控件技巧
- Oracle用户,权限,角色以及登录管理
- asp.net2.0 站点登录,导航与权限管理,角色及用户信息存储于SQL2000的的方法。
- 【TFS权限管理】vs2013 修改TFS已经登录的用户方法
- ASP.NET MVC+EF框架+EasyUI实现权限管理系列(15)-用户登录详细错误和权限数据库模型设计
- 浅析用户权限管理系统中的单点登录