You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 rivejä
2.8 KiB

  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. namespace Basic.Tools
  11. {
  12. /// <summary>
  13. /// 检测会员登录状态
  14. /// </summary>
  15. public class LoginState
  16. {
  17. /// <summary>
  18. /// 判断用户是否登录
  19. /// </summary>
  20. /// <param name="objUserName"></param>
  21. /// <returns></returns>
  22. public static void UserSession()
  23. {
  24. Basic.Model.user muser = Basic.Tools.LoginState.GetUserInfo();
  25. if (muser == null)
  26. {
  27. string URL = "http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.RawUrl;
  28. System.Web.HttpContext.Current.Response.Write("<script>");
  29. System.Web.HttpContext.Current.Response.Write("parent.location.href='login.aspx?jump=" + System.Web.HttpContext.Current.Server.UrlEncode(URL) + "'");
  30. System.Web.HttpContext.Current.Response.Write("</script>");
  31. }
  32. }
  33. /// <summary>
  34. /// 判断管理员是否已经登录(解决Session超时问题)
  35. /// </summary>
  36. public static bool IsUserLogin()
  37. {
  38. //如果Session为Null
  39. if (System.Web.HttpContext.Current.Session[Keys.SESSION_USER_INFO] != null)
  40. {
  41. return true;
  42. }
  43. else
  44. {
  45. //检查Cookies
  46. string username = Basic.Tools.Utils.GetCookie("UserName", "str_key"); //解密用户名
  47. string userpwd = Basic.Tools.Utils.GetCookie("UserPwd", "str_key");//解密密码
  48. if (username != "" && userpwd != "")
  49. {
  50. DAL.user dal = new DAL.user();
  51. Model.user model = dal.GetModel(username, userpwd);
  52. if (model != null)
  53. {
  54. System.Web.HttpContext.Current.Session[Keys.SESSION_USER_INFO] = model;
  55. return true;
  56. }
  57. }
  58. }
  59. return false;
  60. }
  61. /// <summary>
  62. /// 取得管理员信息
  63. /// </summary>
  64. public static Model.user GetUserInfo()
  65. {
  66. if (IsUserLogin())
  67. {
  68. Basic.DAL.user dal = new DAL.user();
  69. Model.user model = System.Web.HttpContext.Current.Session[Keys.SESSION_USER_INFO] as Model.user;
  70. model = dal.GetModel(model.id);
  71. if (model != null)
  72. {
  73. return model;
  74. }
  75. }
  76. return null;
  77. }
  78. }
  79. }