用户控件用户登录判断

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

使用用户控件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成员用来返回用户是否已经登录

把这个用户控件直接拖放到每一个需要登录的页面上,当用户请求该页面时,如果用户未登录,将转到登录页面,如果已经登录,则正常浏览。

是不是很方便呢?

还可以在上面代码标注的地方进行用户对请求页面的权限的判断和指定页面的通用样式(如果事先没有指定样式的话)。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航