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.

76 regels
2.3 KiB

3 jaren geleden
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI.WebControls;
  6. /// <summary>
  7. /// HuiyuanPage 会员中心通用判断是否登录
  8. /// </summary>
  9. ///
  10. namespace Basic
  11. {
  12. public class HuiyuanPage : System.Web.UI.Page
  13. {
  14. public HuiyuanPage()
  15. {
  16. this.Load += new EventHandler(HuiyuanPage_Load);
  17. }
  18. private void HuiyuanPage_Load(object sender, EventArgs e)
  19. {
  20. //判断管理员是否登录
  21. if (!IsUserLogin())
  22. {
  23. string _weburl = Basic.Tools.WebInfo.weburl();
  24. Response.Write("<script>parent.location.href='" + _weburl + "/member/login.htm'</script>");
  25. Response.End();
  26. }
  27. }
  28. /// <summary>
  29. /// 判断会员是否登录
  30. /// </summary>
  31. public bool IsUserLogin()
  32. {
  33. //如果Session为Null
  34. if (System.Web.HttpContext.Current.Session[Keys.SESSION_USER_INFO] != null)
  35. {
  36. return true;
  37. }
  38. else
  39. {
  40. //检查Cookies
  41. string username = Basic.Tools.Utils.GetCookie("UserName", "str_key");
  42. string userpwd = Basic.Tools.Utils.GetCookie("UserPwd", "str_key");
  43. if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(userpwd))
  44. {
  45. DAL.user dal = new DAL.user();
  46. Model.user model = dal.GetModel(username, userpwd);
  47. if (model != null)
  48. {
  49. System.Web.HttpContext.Current.Session[Keys.SESSION_USER_INFO] = model;
  50. return true;
  51. }
  52. }
  53. }
  54. return false;
  55. }
  56. /// <summary>
  57. /// 取得管理员信息
  58. /// </summary>
  59. public Model.user GetUserInfo()
  60. {
  61. if (IsUserLogin())
  62. {
  63. Model.user model = Session[Keys.SESSION_USER_INFO] as Model.user;
  64. if (model != null)
  65. {
  66. return model;
  67. }
  68. }
  69. return null;
  70. }
  71. }
  72. }