ASP

本类阅读TOP10

·asp常用数据库连接方法和技巧
·无组件生成BMP验证码
·一些常用的辅助代码 (网络收藏)
·JavaScript实现的数据表格:冻结列、调整列宽和客户端排序
·VisualStudio.NET_2003及其 MSDN 下载地址
·ASP模拟MVC模式编程
·图片以二进制流输出到网页
·MD5加密算法 ASP版
·ASP.NET编程中的十大技巧
·改进 ASP 的字符串处理性能

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
用户控件用户登录判断

作者:未知 来源:月光软件站 加入时间:2005-2-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;

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



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

是不是很方便呢?

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




相关文章

相关软件