用于权限是复选框选择的后台权限验证
using System;
namespace baitang.util
{
/// <summary>
/// 验证登陆。
/// </summary>
public class CheckGrade
{
public CheckGrade()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// 验证是否登陆及权限
/// </summary>
/// <param name="str">本页需要的权限</param>
public static string IsGrade(String str)
{
System.Console.Write(System.Web.HttpContext.Current.Session["Poplist"]);
if(System.Web.HttpContext.Current.Session["Poplist"]==null)
{
return "<script>alert('对不起,您还未登陆或已超时,请重新登陆!');window.location.href='/Manager/exit.aspx';</script>";
}
else
{
if(System.Web.HttpContext.Current.Session["Poplist"].ToString().IndexOf(str)<0)
{
return "<script>alert('对不起,您没有执行此操作的权限');history.go(-1);</script>";
}
}
return "";
}
}
}
后台权限管理页例:
<input id="G0101" type="checkbox" value="[G0101]" name="Grade" <%if(PopListTmp.IndexOf("[G0101]") >= 0){Response.Write("Checked");} %> />新闻分类</td>
<td style=" 100px"><input id="G0102" type="checkbox" value="[G0102]" name="Grade" <%if(PopListTmp.IndexOf("[G0102]") >= 0){Response.Write("Checked");} %> />新闻列表</td>
<td style=" 100px"><input id="G0103" type="checkbox" value="[G0103]" name="Grade" <%if(PopListTmp.IndexOf("[G0103]") >= 0){Response.Write("Checked");} %> />最新活动</td>
这里权限数据两边加中括号的原因:
以前用纯数据表示权限,权限1到20的话,用上面的权限判断方法,1,10,11在IndexOf判断上会出问题,于是变成了[1],[10],[11],这样便于判断,当然上面以字母G打头而且数据长度相同就不会出现这种问题了,但写习惯了,也加了[],呵呵