用於許可權是複選框選擇的後台許可權驗證
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="width: 100px"><input id="G0102" type="checkbox" value="[G0102]" name="Grade" <%if(PopListTmp.IndexOf("[G0102]") >= 0){Response.Write("Checked");} %> />新聞列表</td>
<td style="width: 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打頭而且資料長度相同就不會出現這種問題了,但寫習慣了,也加了[],呵呵