skip to Main Content

I have Visual Studio Professional 2019, licensed, in a Windows Server 2019 virtual machine.

I have moved a project from my computer to the server, but when debugging, the session variables are lost between methods; in my pc they were working fine with Visual Studio Community 2019. I have tried disabling antivirus but still doesnt work.

This is the code where I save the value in the Session:

if (nombre != null)
                {
                    Session["Usuario"] = nombre;

                }

                ViewBag.error = "";
                return RedirectToAction("Inicio");

            }
            else
            {

                ViewBag.error = "Usuario o contraseƱa incorrectos";
                return View("login");

But when checking the Session in the view, there is no ["Usuario"] array.

I execute it in debug mode, IIS Express Chrome. Dont know if it could interfere, but I
have installed in the same machine the IIS.

2

Answers


  1. Chosen as BEST ANSWER

    I have finally made it work. I tried commenting this line in my web.config

    <sessionState mode="InProc" cookieless="false" timeout="2400"/>

    And the variables started working again


  2. IIS6 joins the function of application pool to recycle some useless processes. When the application pool is caused by errors in website programs or too many visits, the process will be automatically recycled to prevent the website from entering the "crash" state. At this time, The recycling of the application pool will cause the session variable to be cleared, and the session variable will disappear.
    In order to solve this problem, we start the ASP.NET State Service service on the server side, and make some changes in the system’s machine.config. The session state mode is now StateServer by default. If you also have a web.config configuration file in the root directory of your website, please change mode="InProc" to mode="StateServer", and the following code can prevent the loss of session variables:

    <sessionState mode="InProc" cookieless="false" timeout="60"/>

    Change to

    <sessionState
    mode="StateServer"
    stateConnectionString="tcpip=127.0.0.1:42424"
    sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
    cookieless="false"
    timeout="20"
    />
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search