newusereser
newusereser

Reputation: 33

Active users are changing

i have a web application. It has about 25-30 webforms and i publish it with iis on network to users. My problem is "a" user logged on and using application then "b" user is logging in and suddenly "a" user becomes "b" user. How can i solve this?

I tried session and get & set methods for user id but still changing users on network.

this is login page,

        cn.Open();

        SqlCommand cmd = new SqlCommand("select id, sifre,aktif from Kullanici where id='" + TextBox1.Text + "' and sifre='" + TextBox2.Text + "' and aktif='1'", cn);
        SqlDataReader dr = cmd.ExecuteReader();
        string login = TextBox1.Text;
        string pwd = TextBox2.Text;
        bool bayrak = false;
        while (dr.Read())
        {
            bayrak = true;
            if ((dr["id"].ToString() == login) && (dr["sifre"].ToString() == pwd) && (dr["aktif"].ToString() == "1"))
            {
                Session["id"] = login;

                Response.Redirect("~/WebForm2.aspx");
            }

        }

and this is webform2 code

        WebForm1 form1 = new WebForm1();

        kullanici = Session["id"].ToString();

        if (IsPostBack == false)
        {



            cn.Open();
            SqlCommand komutad = new SqlCommand("select ad from kullanici where id='" + kullanici + "'", cn);
            SqlCommand komutsoyad = new SqlCommand("select soyad from kullanici where id='" + kullanici + "'", cn);
            SqlCommand komutadmin = new SqlCommand("select admin from kullanici where id='" + kullanici + "'", cn);
            try{
                name = komutad.ExecuteScalar().ToString();
            surname = komutsoyad.ExecuteScalar().ToString();
            admin = komutadmin.ExecuteScalar().ToString();
            }
        catch
        {
            Response.Redirect("~/WebForm1.aspx");
        }
            DateTime tarih = DateTime.Today;

            Label1.Text = tarih.ToString().Substring(0, 10) + " --- Welcome " + name + " " + surname;
            cn.Close();

            if (admin == "0" && TreeView1.Nodes.Count == 4)
            {
                TreeView1.Nodes.RemoveAt(0);
            }
        }

name and surname becomes the last login user on every user.

Upvotes: 0

Views: 48

Answers (1)

Mohit Munjal
Mohit Munjal

Reputation: 25

Dont Use Static Variable in Web Application http://www.foliotek.com/devblog/avoid-static-variables-in-asp-net/

Upvotes: 1

Related Questions