Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
    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)
           {
                    .............
            }
}
}


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
Posted
Comments
Salman622 5-Dec-15 2:06am    
what happening in your case is
when first user logs in
your security Class stores the information of first user because the variables are static when the second user logs in the values changes as per the second user
and all the user logged in will use the the values of the user who login last.
so here you have to change your logic of storing the value of dept.
instead of storing the values in static variable you can store the values in session and your problem will be solve
Tomas Takac 5-Dec-15 2:38am    
You should post that as an solution.

1 solution

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.
 
Share this answer
 
Comments
abdul subhan mohammed 5-Dec-15 5:40am    
any other solution, other than Sessions?
Session is the concept for this only. I don't know any other solutions. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900