自己寫的後台靜態許可權驗證類

來源:互聯網
上載者:User

用於許可權是複選框選擇的後台許可權驗證
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打頭而且資料長度相同就不會出現這種問題了,但寫習慣了,也加了[],呵呵

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.