使用用户控件whelogined.ascx,代码如下:
namespace hezjs.webform.modules.ascx
{
using system;
using system.data;
using system.drawing;
using system.web;
using system.web.ui.webcontrols;
using system.web.ui.htmlcontrols;
/// <summary>
/// modwhelogined 的摘要说明。
/// </summary>
public class modwhelogined : system.web.ui.usercontrol
{
private void page_load(object sender, system.eventargs e)
{
// 在此处放置用户代码以初始化页面
string strpath = hezjs.webform.wffunction.siteurl(this.parent.page) + "modules/aspx/modlogin.aspx";
if (this.session["转入页"] == null)
this.session.add("转入页", this.parent.page.request.rawurl);
else
this.session["转入页"] = this.parent.page.request.rawurl;
if (this.session["用户"] != null)
{
if (((hezjs.sys.sysuser)this.session["用户"]).logined)
{
//判断权限
//指定样式
}
else
{
this.response.redirect(strpath);
}
}
else
this.response.redirect(strpath);
}
#region web 窗体设计器生成的代码
override protected void oninit(eventargs e)
{
//
// codegen: 该调用是 asp.net web 窗体设计器所必需的。
//
initializecomponent();
base.oninit(e);
}
/// <summary>
/// 设计器支持所需的方法 – 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void initializecomponent()
{
this.load += new system.eventhandler(this.page_load);
}
#endregion
}
}
strpath用来指定系统登录界面,hezjs.webform.wffunction.siteurl()方法用来返回网站地址
session["转入页"]中存放用户请求的页面的地址
session["用户"]中存放一个hezjs.sys.sysuser对象,该对象包括一个logined成员用来返回用户是否已经登录
把这个用户控件直接拖放到每一个需要登录的页面上,当用户请求该页面时,如果用户未登录,将转到登录页面,如果已经登录,则正常浏览。
是不是很方便呢?
还可以在上面代码标注的地方进行用户对请求页面的权限的判断和指定页面的通用样式(如果事先没有指定样式的话)。
