Problems with values passed to static variables with class on server

1

Good morning everyone.

I am currently suffering from a problem and can not find the solution. I have a login system in ASP.NET C # when I do the authentication everything happens correctly only so that's the problem I need to get the ID value from my database from the user who was authenticated there by that time until the method that I use works, I review the value of the ID captured at login time for a public static variable in a class and it redirects me to the start screen that is correct with the value in the variable .. and then the problem happens, this variable does not save the value to the client's computer but in the server then when someone logs in to the site all the people who access this site will be automatically logged in this login all this because of the static variable in the class someone knows how to solve it is situation that is eating judgment.

Thank you in advance !! Kennedy

In my Global class

                 public static int Cod_Login;

My login validation

                DataSet DS = new DataSet();
                DS = ValidaLogin(TxtUsuario.Text, TxtSenha.Text);
                for (int i = 0; i < DS.Tables[0].Rows.Count; i++)
                 {
                 Cod_User = Convert.ToInt32(DS.Tables[0].Rows[i][0] == DBNull.Value ? 0 :                                         DS.Tables[0].Rows[i][0]);
                }

                if (Cod_User != 0)
                {
                    Class_Global.Cod_Login = Cod_User; //aonde passo o valor para a variavel
                    Response.Redirect("/Default.aspx");
                }
                else
                {
                    LblMsg.Text = "CPF e/ou Senha incorretos.";
                    LblMsg.Visible = true;
                }

On my home page after login

                if (Class_Global.Cod_Login != 0)
                                {

                //aqui utilizo se o meu código caso for o valor diferente de zero

                }
    
asked by anonymous 10.08.2018 / 08:22

2 answers

0

Complementing the response from @CarlosAlmeida , you can save the value in session, but if you want to keep the page "alive" for more than 20 minutes, you should set timeout of the session to its web.config :

<configuration>
  <system.web>
     <sessionState timeout="60"></sessionState>
  </system.web>
</configuration>

In this way, session values are stored in memory for 60 minutes .

    
10.08.2018 / 10:39
0

I assume you are using Web Form. If I understood the problem, I think the resolution is to pass through session variables.

Session("ID_USER") = valor;
    
10.08.2018 / 10:01