C#自定义用户浏览网页权限
来源:互联网 发布:unity3d 5.x下载 编辑:程序博客网 时间:2024/05/21 09:53
using System;
using System.Collections.Generic;
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;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
/// <summary>
///PageBase 的摘要说明
/// </summary>
public class AdminPageBase:System.Web.UI.Page
{
//查找用户类型
public int UserType()
{
SqlConnection cn = conn.CreateConnection();
cn.Open();
SqlCommand cmd = new SqlCommand("select [UserType] from [Members] where [UserName]='" + Session["UserName"].ToString() + "' and [Password]='" + Session["PassWord"].ToString() + "'", cn);
int i = Convert.ToInt32(cmd.ExecuteScalar());
return i;
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.Load += new System.EventHandler(PageBase_Load);
this.Error += new System.EventHandler(PageBase_Error);
}
//错误处理
protected void PageBase_Error(object sender, System.EventArgs e)
{
string errMsg = string.Empty;
Exception currentError = HttpContext.Current.Server.GetLastError();
errMsg += "<h1>系统错误:</h1><hr/>系统发生错误, " +
"该信息已被系统记录,请稍后重试或与管理员联系。<br/>" +
"错误地址: " + Request.Url.ToString() + "<br/>" +
"错误信息: " + currentError.Message.ToString() + "<hr/>" +
"<b>Stack Trace:</b><br/>" + currentError.ToString();
HttpContext.Current.Response.Write(errMsg);
Server.ClearError();
}
private void PageBase_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (HttpContext.Current.Session["UserName"] != null && HttpContext.Current.Session["PassWord"] != null)
{
if (UserType()<3)
{
HttpContext.Current.Response.Write("<script> alert('您不是管理员,没有访问权限!');location='/resdc/Default.aspx'</script>");
}
}
else
{
HttpContext.Current.Response.Write("<script> alert('您未登录,目前没有权限访问!');location='/resdc/Default.aspx'</script>");
}
}
}
}
网页页面中调用方法:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Admin_Default : AdminPageBase //把继承接口System.Web.UI.Page改为AdminPageBase
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
- C#自定义用户浏览网页权限
- C#浏览网页源代码
- 用户浏览网页的流程
- 用户浏览网页的过程
- apache实现网页浏览权限设置
- apache实现网页浏览权限设置
- 利用Filter限制用户浏览权限
- 自定义用户访问权限
- onpageshow 用户浏览网页时触发
- MVC自定义AuthorizeAttribute管理页面浏览权限
- 浏览——用户自定义路径
- C#的WebBrowser控件浏览网页
- 从F型网页浏览看用户对网页…
- 从F型网页浏览看用户对网页的浏览习惯
- C# 自定义用户控件
- C# 自定义用户控件
- C# 自定义用户控件
- C#自定义用户控件
- 面向接口编程详解
- Objective-c的@property 详解
- GBin1专题之Web热点#6
- 整数的转换成2进制有多少个1
- Extjs 解决乱码
- C#自定义用户浏览网页权限
- 理解栈帧
- 通信行业应届毕业生起薪【2012年新版】
- 在升序数组中查找和等于给定值的两个数
- ssh2项目例子(政府类)
- 建设项目经济评价信息化手段
- 和为n的连续正数序列
- 32位和64位的区别--深入理解计算机系统笔记一
- macvim