一聚教程网:一个值得你收藏的教程网站

热门教程

用户控件用户登录判断

时间:2022-06-30 10:01:28 编辑:袖梨 来源:一聚教程网

使用用户控件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;
///
/// modWheLogined 的摘要说明。
///

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);
}

///
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
///

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
strPath用来指定系统登录界面,HEZjs.WebForm.wfFunction.SiteUrl()方法用来返回网站地址
Session["转入页"]中存放用户请求的页面的地址
Session["用户"]中存放一个HEZjs.Sys.sysUser对象,该对象包括一个Logined成员用来返回用户是否已经登录
把这个用户控件直接拖放到每一个需要登录的页面上,当用户请求该页面时,如果用户未登录,将转到登录页面,如果已经登录,则正常浏览。
是不是很方便呢?
还可以在上面代码标注的地方进行用户对请求页面的权限的判断和指定页面的通用样式(如果事先没有指定样式的话)。

热门栏目