它是安全通过静态对象的静态属性来访问asp.net会话变量? [英] Is it safe to access asp.net session variables through static properties of a static object?

查看:152
本文介绍了它是安全通过静态对象的静态属性来访问asp.net会话变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它是安全的,通过一个静态对象的静态属性访问asp.net会话变量?

Is it safe to access asp.net session variables through static properties of a static object?

下面是我的意思是:

public static class SessionHelper
{
    public static int Age
    {
        get
        {
            return (int)HttpContext.Current.Session["Age"];
        }

        set
        {
            HttpContext.Current.Session["Age"] = value;
        }
    }


    public static string Name
    {
        get
        {
            return (string)HttpContext.Current.Session["Name"];
        }

        set
        {
            HttpContext.Current.Session["Name"] = value;
        }
    }
}

有没有可能是用户A可以访问用户B的会话数据的这种方式?

Is it possible that userA could access userB's session data this way?

推荐答案

是的,这样是好的 - 只要确保你的不要做到这一点:

Yes, that way is fine - just make sure you don't do this:

public static class SessionHelper
{

    private static HttpSession sess = HttpContext.Current.Session;
    public static int Age
    {
        get
        {
            return (int)sess["Age"];
        }

        set
        {
            sess["Age"] = value;
        }
    }
}

由于香港专业教育学院看到这种方式显示一个用户的会话数据给其他用户。 (尽管在ASP.NET 1.1)

As ive seen this way show one user's session data to another user. (Albeit in ASP.NET 1.1)

这篇关于它是安全通过静态对象的静态属性来访问asp.net会话变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆