用户控件用户登录判断

使用用户控件wheLogined.ascx,代码如下:


None.gif namespace  HEZjs.WebForm.modules.ascx 
ExpandedBlockStart.gifContractedBlock.gif
dot.gif
InBlock.gif 
using System; 
InBlock.gif 
using System.Data; 
InBlock.gif 
using System.Drawing; 
InBlock.gif 
using System.Web; 
InBlock.gif 
using System.Web.UI.WebControls; 
InBlock.gif 
using System.Web.UI.HtmlControls; 
ExpandedSubBlockStart.gifContractedSubBlock.gif 
/**//// <summary> 
InBlock.gif 
///  modWheLogined 的摘要说明。 
ExpandedSubBlockEnd.gif 
/// </summary> 

InBlock.gif public class modWheLogined : System.Web.UI.UserControl 
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif
InBlock.gif
InBlock.gif  
private void Page_Load(object sender, System.EventArgs e) 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif
InBlock.gif   
// 在此处放置用户代码以初始化页面 
InBlock.gif

InBlock.gif   
string strPath = HEZjs.WebForm.wfFunction.SiteUrl(this.Parent.Page) + "modules/aspx/modLogin.aspx"
InBlock.gif
InBlock.gif   
if (this.Session["转入页"== null
InBlock.gif    
this.Session.Add("转入页"this.Parent.Page.Request.RawUrl); 
InBlock.gif   
else 
InBlock.gif    
this.Session["转入页"= this.Parent.Page.Request.RawUrl; 
InBlock.gif
InBlock.gif   
if (this.Session["用户"!= null
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif
InBlock.gif    
if (((HEZjs.Sys.sysUser)this.Session["用户"]).Logined) 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif
InBlock.gif     
//判断权限 
InBlock.gif     
//指定样式      
ExpandedSubBlockEnd.gif
    }
 
InBlock.gif    
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif
InBlock.gif     
this.Response.Redirect(strPath); 
ExpandedSubBlockEnd.gif    }
 
ExpandedSubBlockEnd.gif   }
 
InBlock.gif   
else 
InBlock.gif    
this.Response.Redirect(strPath); 
InBlock.gif
ExpandedSubBlockEnd.gif  }
 
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif  
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码 
InBlock.gif  
override protected void OnInit(EventArgs e) 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif
InBlock.gif   
// 
InBlock.gif   
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 
InBlock.gif   
// 
InBlock.gif
   InitializeComponent(); 
InBlock.gif   
base.OnInit(e); 
ExpandedSubBlockEnd.gif  }
 
InBlock.gif   
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary> 
InBlock.gif  
///  设计器支持所需的方法 - 不要使用代码编辑器 
InBlock.gif  
///  修改此方法的内容。 
ExpandedSubBlockEnd.gif  
/// </summary> 

InBlock.gif  private void InitializeComponent() 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif
InBlock.gif   
this.Load += new System.EventHandler(this.Page_Load); 
InBlock.gif
ExpandedSubBlockEnd.gif  }
 
ExpandedSubBlockEnd.gif  
#endregion
 
ExpandedSubBlockEnd.gif }
 
ExpandedBlockEnd.gif}
 
None.gif
None.gif





strPath用来指定系统登录界面,HEZjs.WebForm.wfFunction.SiteUrl()方法用来返回网站地址
Session["转入页"]中存放用户请求的页面的地址
Session["用户"]中存放一个HEZjs.Sys.sysUser对象,该对象包括一个Logined成员用来返回用户是否已经登录



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

是不是很方便呢?

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



14.gif 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值