您现在的位置是:网站首页> 编程资料编程资料
为每个页面加上Session判断的小例子_实用技巧_
2023-05-24
347人已围观
简介 为每个页面加上Session判断的小例子_实用技巧_
首先新建一个类,继承自System.Web.UI.Page,然后重写OnInit,如下:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace FuSession
{
public class JudgeSession : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (Session.Keys.Count <= 0)
{
Response.Redirect("~/TiaoZh.htm", true);
}
else
{
if (Session["UserId"] == null && Session["Qx"] == null && Session["Dept"] == null && Session["UserName"] == null && Session["QxType"]==null)
{
Response.Redirect("~/TiaoZh.htm", true);
}
}
}
}
}
在页面中按照如下方法引用即可。
public partial class QrDeptMan_Home : FuSession.JudgeSession
相关内容
- C#和asp.net中链接数据库中参数的几种传递方法实例代码_实用技巧_
- GridView中checkbox"全选/取消"完美兼容IE和Firefox_实用技巧_
- 使用DataTable.Select 方法时,特殊字符的转义方法分享_实用技巧_
- ASP.NET ASHX中获得Session的方法_实用技巧_
- ASP.NET 实现验证码以及刷新验证码的小例子_实用技巧_
- xls表格导入数据库功能实例代码_实用技巧_
- CHECKBOX 的全选、取消及跨页保存的实现方法_实用技巧_
- 删除特殊字符和限定用户输入长度的示例代码_实用技巧_
- 数据绑定之DataFormatString使用介绍_实用技巧_
- TreeView无刷新获取text及value实现代码_实用技巧_
