LoginLogic.cs
上传用户:simon2hong
上传日期:2021-11-18
资源大小:16746k
文件大小:5k
源码类别:

OA系统

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10. /// <summary>
  11. /// LoginLogic 的摘要说明
  12. /// </summary>
  13. public class LoginLogic
  14. {
  15. public LoginLogic()
  16. {
  17. }
  18.     /// <summary>
  19.     /// 判断后登录
  20.     /// </summary>
  21.     /// <param name="TopRootStr">输入路径</param>
  22.     /// <param name="ClassName">类名</param>
  23.     public static void MatchLoad(string TopRootStr,string ClassName)
  24.     {
  25.         //SessionInclude.SessionId = "admin";//临时值
  26.         //SessionInclude.Id = "1";//临时值
  27.         if (!string.IsNullOrEmpty(CookieInclude.CookieId))
  28.         {
  29.             SessionInclude.SessionId = CookieInclude.CookieId;
  30.             SessionInclude.Id = CookieInclude.Id;
  31.         }
  32.      
  33.         object userObj = SessionInclude.SessionId;
  34.         if (userObj == null)
  35.         {
  36.             HttpContext.Current.Response.Redirect(TopRootStr + "Login.aspx");
  37.         }
  38.         if (CannotUse(ClassName))
  39.         {
  40.             HttpContext.Current.Response.Redirect(TopRootStr + "SystemError.aspx");
  41.         }
  42.     }
  43.     public static bool CannotUse(string ClassName)
  44.     {
  45.         bool IsCannotUse = false;
  46.     Model.Users MU=new BLL.Users().GetModel(int.Parse(SessionInclude.Id));
  47.     Model.User_Priv MUP = new BLL.User_Priv().GetModel(MU.PrivId);
  48.     string[] QXStr = MUP.FuncIdStr.Split(new string[]{","},StringSplitOptions.RemoveEmptyEntries);
  49.     foreach (string QX in QXStr)
  50.     {
  51.         if (QX == ClassName)
  52.        {
  53.            IsCannotUse = true;
  54.            break;
  55.        }
  56.     }
  57.     return IsCannotUse;
  58.     }
  59. }
  60. /// <summary>
  61. /// Cookies属性操作类
  62. /// </summary>
  63. public class CookieInclude
  64. {
  65.     public CookieInclude()
  66.     {
  67.     }
  68.     /// <summary>
  69.     /// 用户的CookiesID属性
  70.     /// </summary>
  71.     public static string CookieId
  72.     {
  73.         set
  74.         {
  75.             HttpContext.Current.Response.Cookies["oa_cookiename"].Value = HttpContext.Current.Server.UrlEncode(value);
  76.             HttpContext.Current.Response.Cookies["oa_cookiename"].Expires = DateTime.Now.AddDays(365);
  77.         }
  78.         get
  79.         {
  80.             try
  81.             {
  82.                 return HttpContext.Current.Server.UrlDecode(HttpContext.Current.Request.Cookies["oa_cookiename"].Value);//通过索引来获取值
  83.             }
  84.             catch (Exception exp)
  85.             {
  86.                 if (exp is System.NullReferenceException)
  87.                 {
  88.                     return "";
  89.                 }
  90.                 else
  91.                 {
  92.                     throw exp;
  93.                 }
  94.             }
  95.         }
  96.     }
  97.     /// <summary>
  98.     /// 用户的CookiesID属性
  99.     /// </summary>
  100.     public static string Id
  101.     {
  102.         set
  103.         {
  104.             HttpContext.Current.Response.Cookies["oa_cookieId"].Value = value;
  105.             HttpContext.Current.Response.Cookies["oa_cookieId"].Expires = DateTime.Now.AddDays(365);
  106.         }
  107.         get
  108.         {
  109.             try
  110.             {
  111.                 return HttpContext.Current.Request.Cookies["oa_cookieId"].Value;//通过索引来获取值
  112.             }
  113.             catch (Exception exp)
  114.             {
  115.                 if (exp is System.NullReferenceException)
  116.                 {
  117.                     return "";
  118.                 }
  119.                 else
  120.                 {
  121.                     throw exp;
  122.                 }
  123.             }
  124.         }
  125.     }
  126.     /// <summary>
  127.     /// 清楚Cookies的ID
  128.     /// </summary>
  129.     public static void Clear()
  130.     {
  131.         HttpContext.Current.Response.Cookies["oa_cookiename"].Expires = DateTime.Now.AddDays(-1);
  132.     }
  133. }
  134. /// <summary>
  135. /// Session属性操作类
  136. /// </summary>
  137. public class SessionInclude
  138. {
  139.     /// <summary>
  140.     /// 用户的用户ID属性
  141.     /// </summary>
  142.     public static string SessionId
  143.     {
  144.         set
  145.         {
  146.             HttpContext.Current.Session["AdminUser"] = value;
  147.         }
  148.         get
  149.         {
  150.             if (HttpContext.Current.Session["AdminUser"] != null)
  151.             {
  152.                 return HttpContext.Current.Session["AdminUser"].ToString();
  153.             }
  154.             else
  155.             {
  156.                 return null;
  157.             }
  158.         }
  159.     }
  160.     /// <summary>
  161.     /// 用户的ID属性
  162.     /// </summary>
  163.     public static string Id
  164.     {
  165.         set
  166.         {
  167.             HttpContext.Current.Session["AdminUserId"] = value;
  168.         }
  169.         get
  170.         {
  171.             if (HttpContext.Current.Session["AdminUserId"] != null)
  172.             {
  173.                 return HttpContext.Current.Session["AdminUserId"].ToString();
  174.             }
  175.             else
  176.             {
  177.                 return null;
  178.             }
  179.         }
  180.     }
  181. }