session variables losing value in deployed application - asp.net

When application is deployed on server and accessed from the client, the session variables are blank
If IsNothing(Session("Order")) Then is always returning true.
The session variables have values when tested on the development machine.
This is the entry in web.config
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="true" timeout="60" />

When are you setting the session? Also, is this hosted? Some 3rd party hosts recycle worker processes/application pools constantly and it kills your session. Make sure you have your own application pool as well. Also, cookieless could be a problem for you.

Related

Session variables lost ASP.Net

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.
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
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"
/>

Don't want to share session

I have two ASP.net MVC applications say a.xyz.com/Customer and a.xyz.com/CustomerTest.
I have implemented cookie-based FormsAuthentication. Name of Auth cookie (AUTH and AUTHTEST) is different in both the Applications. Problem is that when I browse the applications in same browser, Session Cookies are available in both the apps. Also when I Abandon session in one application, second application's session abandons as well.
Both applications are running under same app pool. I cannot change the app Pool as they are having rewrite rules also which will not be available if I change the app pool.
I don't want to share the session between these two applications.
Please let me know if it is possible and How?
It is done.
I have changed the session cookie name of both the Applications in sessionState.
<sessionState mode="InProc" cookieless="false" timeout="60" cookieName="PRODSession" />
<sessionState mode="InProc" cookieless="false" timeout="60" cookieName="TestSession" />

Session Time Out in Asp.net 4.0 on IIS 7.5

I want to set timeout for my web application for 12 hours.
I have done setting in web.config file as:
<system.web>
<sessionState timeout="720" />
</system.web>
As suggested in the following post:
I came to know that the Application Pool recycles in every 20 minutes (if the pool is ideal).
And I also checked for changing the application pool time out using one question about application pool timeout setting
But still the session time-out is not set to 720 minutes. Do I need to change machine.config file for changing the session time out.
But I think the properties of machine.config file should be overriden by web.config file.
Kindly provide me some idea.
You can try out WMI(Windows Management Instrumentation) script it can help you.You need to have sufficient priveleges to implement the Script.
follwing are the links you can check to get more information.
http://bendera.blogspot.in/2010/12/configuring-ica-rdp-timeout-values.html
http://technet.microsoft.com/en-us/library/cc771956%28v=ws.10%29.aspx
You should set all following:
Application Pool / Advanced Settings. There the option Idle Timeout should be set in minutes.
Then within the web.config file in system.web section you should also set the Authentication/Forms, SessionState and RoleManager timeouts, if applicable.
<authentication mode="Forms"><forms loginUrl="~/default.aspx" name=".ASPXFORMSAUTH" timeout="120" /></authentication>
<sessionState cookieless="AutoDetect" cookieName="TYS_ADMIN_SessionId" timeout="120" />
<roleManager ... cookieTimeout="120" defaultProvider="GMRoleProvider" enabled="true">...</roleManager>

cannot use stateserver mode other than inproc

The most irritating problem i've come across. I have an asp.net mvc application with sessionstate mode to stateserver. On my local machine and my old server iis6 it worked but i recently changed to a new server running iis7 and now the line:
<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" timeout="20" />
doesn't do anything. Even when I set the value in the connectionstring to something that doesn't exist it is ignored and thus it's using inproc only.
All my webapps under iis have the same problem.
I've also tried sqlserver mode with the same result. it just gets ignored.
Why oh why??
There's a place in IIS where you can disable InProcess session state.
These articles should point you in the right direction:
http://technet.microsoft.com/en-us/library/cc732964%28WS.10%29.aspx
http://technet.microsoft.com/en-us/library/cc725624%28WS.10%29.aspx

how to use state server for session in asp.net 2.0

I need to know the procedure to use asp.net session state server for session.
Please help.
You need to:
Start the stat session windows service
Add the following entry to your web.config file:
<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" cookieless="UseCookies" timeout="10" regenerateExpiredSessionId="true" />
Configure the values in the above entry according to this
Note that if you used to use the inProc sessions before, you will not be able to store non serializable objects in session anymore.
Here's a very good article on Code Project which will step-by-step guide you how to do this..
http://www.codeproject.com/KB/aspnet/ExploringSession.aspx

Resources