Problems with values passed to Static variables with class on the server

Asked

Viewed 121 times

1

Good morning, everyone.

I am currently suffering from a problem and cannot find the solution. I have a login system in ASP.NET C# when I do the authentication everything happens correctly only that there is the problem I need to get the ID value of my database from the user who was authenticated there for that time until the method I use works, i pass the value of the captured ID at login to 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 for the client’s computer and yes on the server so 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 fix it situation that is in eating the judgment.

Thank you from now on!! 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;
                }

In 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

                }

2 answers

0

I assume you’re using Web Form. If I understand the problem, I think the resolution is to go through session variables.

Session("ID_USER") = valor;
  • I did it worked, but out of nowhere incredibly the Sesame loses its value...

  • I used Session again with the tip from the friend below and managed to keep Session thanks to you...

  • Add the following line to the Global_asax.Vb file at Session_start. Session.Timeout = 1500

0


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

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

This way the session values are stored in memory during 60 minutes.

  • I’ll test to keep her alive

  • I didn’t know this thanks for the help was very helpful, my problem was that Session got lost when I was updating the page...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.