用户控件用户登录判断
使用用户控件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);
}
Web 窗体设计器生成的代码
}
}
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
strPath用来指定系统登录界面,HEZjs.WebForm.wfFunction.SiteUrl()方法用来返回网站地址
Session["转入页"]中存放用户请求的页面的地址
Session["用户"]中存放一个HEZjs.Sys.sysUser对象,该对象包括一个Logined成员用来返回用户是否已经登录
把这个用户控件直接拖放到每一个需要登录的页面上,当用户请求该页面时,如果用户未登录,将转到登录页面,如果已经登录,则正常浏览。
是不是很方便呢?
还可以在上面代码标注的地方进行用户对请求页面的权限的判断和指定页面的通用样式(如果事先没有指定样式的话)。
Life is like a boat, and I'm at sea.