c#在主页上设置覆盖用户

在c#的 MasterPage 中,使用 get set属性可以检索访问该网站的每个用户的电子邮件地址:

    public static string TheObjectPropertyEmail { get; private set; }    

    ...

    TheObjectPropertyEmail = reader["Email"].ToString();

在具有 MasterPage Default.asp.cs 页面上,恢复通过以下方式访问网站的每个用户的电子邮件地址:

Mp.TheObjectPropertyEmail

但是我已经尝试过,如果访问是由用户通过电子邮件 foo@foo.com 执行的,几秒钟后访问是通​​过用户通过电子邮件 foo2@foo.com进行的(当代访问),第二次访问将覆盖 foo@foo.com 的第一次访问,并显示最后一次访问该网站的信息...

该如何解决?

我在做什么错了?

请你能帮我吗?

编辑#01

public static class MailContainer
    {
        public static string TheObjectPropertyEmail
        {
            get
            {
                return HttpContext.Current.Session["TheObjectPropertyEmail"].ToString();
            }
            private set
            {
                HttpContext.Current.Session["TheObjectPropertyEmail"] = value;
            }
         } 
    }

  MailContainer.TheObjectPropertyEmail = reader["Email"].ToString();
rabbitcf 回答:c#在主页上设置覆盖用户

U必须创建一个公共静态类才能访问变量。 由于MasterPage类不是静态的,因此无法访问MasterPage中的TheObjectPropertyEmail。

namespace xxxxx
{
    public static class MailContainer
    {
        public static string TheObjectPropertyEmail
        {
            get
            {
                return HttpContext.Current.Session["TheObjectPropertyEmail"].ToString();
            }
            set
            {
                HttpContext.Current.Session["TheObjectPropertyEmail"] = value;
            }
         } 
    }
}

使用:

xxxxx.MailContainer.TheObjectPropertyEmail
本文链接:https://www.f2er.com/2958519.html

大家都在问