C#中的类问题 [英] Problem with class in C#

查看:70
本文介绍了C#中的类问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在c#中有一个asp.net网站。



其中我为安全创建了一个类。

例如:我有部门和分支页面。

在Security_Bl我已经为部门分支声明了四个公共成员。



Hi guys,

I have a asp.net website in c#.

Where i have created a class for Security.
for eg: i have department and branch page.
In Security_Bl i have declare four public members for dept n branch.

Security_Bl.class

    public static bool deptInsert { get; set; }
    public static bool deptView { get; set; }
    public static bool deptUpdate { get; set; }
    public static bool deptDelete { get; set; }

    public static bool BranchInsert { get; set; }
    public static bool BranchView { get; set; }
    public static bool BranchUpdate { get; set; }
    public static bool BranchDelete { get; set; }

if (dt.Rows[0]["Module"].ToString() == "dept")
            {
                deptInsert = Convert.ToBoolean(dt.Rows[0]["OptInsert"].ToString());
                deptView = Convert.ToBoolean(dt.Rows[0]["OptView"].ToString());
                deptUpdate = Convert.ToBoolean(dt.Rows[0]["OptUpdate"].ToString());
                deptDelete = Convert.ToBoolean(dt.Rows[0]["OptDelete"].ToString());
            }
            if (dt.Rows[1]["Module"].ToString() == "Branch")
            {
                BranchInsert = Convert.ToBoolean(dt.Rows[1]["OptInsert"].ToString());
                BranchView = Convert.ToBoolean(dt.Rows[1]["OptView"].ToString());
                BranchUpdate = Convert.ToBoolean(dt.Rows[1]["OptUpdate"].ToString());
                BranchDelete = Convert.ToBoolean(dt.Rows[1]["OptDelete"].ToString());
            }





department.cs



department.cs

    public bool deptInsert = Security_Bl.deptInsert ;

    public bool deptView = Security_Bl.deptView ;

    public bool deptUpdate = Security_Bl.deptUpdate ;

    public bool deptDel = Security_Bl.deptDelete;

 protected void Page_Load(object sender, EventArgs e)
    {
if(deptview)
{
          if(!ispostback)
           {
                    .............
            }
}
}





此应用程序已发布,目前正在互联网上运行。



一个用户有权查看部门页面n一个人没有。



但是,如果两个用户同时登录/工作n其他用户没有

权限查看..他也可以查看该页面。

这是上课或别的问题。



任何人都可以帮助我。





谢谢



this application is published and currently running on internet.

one user have permission to view dept page n one doesn't have.

But when both the users login/working at the same time n other user which do not have
permission to view.. he can also view that page.
is this the problem with class or something else.

can any one please help me.


Thanks

推荐答案

不要使用静态变量,因为它们将被共享。这意味着一旦你初始化它们,任何用户都可以访问它们,并且所有人都可以使用相同的值。



在Web应用程序中,这会产生问题。这就是为什么我们有会话概念,我们存储用户的信息或其他任何不能与其他用户共享的信息。每个用户在服务器上都有唯一的会话,并且不像静态变量那样重叠。
Don't use static variables because they will be shared. Meaning once you initialize them, those can be accessed by any user and the value will be same for all.

In a web app, this creates issues. That's why we have session concept in which we store the user's information or anything else, which can't be shared with other users. Each user has unique session on server and that does not overlap like static variables.


这篇关于C#中的类问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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