Session lost in few seconds randomly - c#

My web application is developed using Dot Net 4.0 C# and MS SQL 2008 R2. Application and Database are deployed on separate servers.
I have used form authentication on my application and user session is maintained in Session object. Recently the session object on my application was getting lost frequently because of no reason.
I've tried below stuffs to fix this, but nothing worked.
Increase the session timeout from web.config
Increase the IDLE Timeout of Application Pool from IIS
Set the number of Worker Process to 1
Proper exception handling for required method and global exception handling
Fixed all exceptions and memory leakage.
Because of some other reason we've restarted our SQL Server Machine today and everything started working perfect now.
I'm confused now on how can a InProc session issue be solved by restarting SQL Server machine.

Related

Application working when app pool refresh in ASP.NET

App pool refresh issue
Application is not working if we do not refresh the app pool (in IIS).
Issue Background
When our ASP.NET application and database (Oracle SQL developer) was migrated to a new server, it started coming for the new app server and DB server before that in old database and application server, it was not starting up.
Our Investigation
We have started our investigation and created a logging table Before and after the Application Pool refresh in this procedure:
osspbs_dba.build_request_pkg.get_requests_sp(in_req_id => :in_req_id,
in_site_id => :in_site_id,
out_cur_requests => :out_cur_requests);
We found the it is throwing a database error while fetching the cursor
Ora-01861.
Later we have logged the parameter and found that when China user works the NLS_TERRITORY and NLS_LANGUAGE is logged in the database according to their session.
But after that when American user started working then NLS_TERRITORY and NLS_LANGUAGE still logging as CHINA and the error started showing up.
This issue is gone when we refresh the application pool on the application server.
Attaching the screen shot of logs:
At line number 15 REQ_ID - 65527 when I access it from my system after the issue came it is logging it as CHINA.
After the Application Pool refresh It is logging as American and working fine.
So in my investigation once this changes to CHINA then it is not changing for other users sessions who are based on America or other locations.
Note: connection pool size also increased in web.config.

How to Gracefully Shut Down ASP.Net (not Core)

I have a WCF service application hosted in IIS. On startup, it reads the SQL connection information from the web.config and connects to the SQL Server to get the necessary information to bootstrap the application. If the SQL Server is unavailable for some reason, we want the service to shutdown - which I currently accomplish by throwing an exception.
The problem we have with this is that, if a service fails to start more than N times, IIS helpfully turns off the application pool - which means that, after the SQL Server connection issue is corrected (possibly entirely external to the IIS server), a sysadmin has to think to go an turn the app pool back on.
What I'd like to do is have the service gracefully exit. I know that there are ways to do this with ASP.Net Core (i.e., ways to hook into the lifecycle management of the process and tell it to exit), but have been unable to find anything like that for .Net Framework/ASP.Net.
Is there such an API that I can use?
Turns out that this method is available and works.
https://learn.microsoft.com/en-us/dotnet/api/system.web.hosting.hostingenvironment.initiateshutdown?view=netframework-4.8

Session expired error on login

We have two windows servers for different environment where the applications are hosted on IISv6.
I host a new site on server one .When we try to login to server one, application through exception SESSION IS GETTING EXPIRED immediately on login button clicks.
We have same binaries on server two and its working fine there.
One more surprise is that same application was hosted 2-3 months earlier and working fine on server one.
The works that I did:
I compared IIS setting on both server.
Re-host website for 2-3 times.
Clear cookies on browser.
Play with session timeout and execution timeout.
Authorization is also enabled for anonymous.
Both server and client machine time are the same
I would like to know, if someone faced the same issue here.
Thanks

ASP.NET MVC Cache is clearing itself

I have a ASP.NET MVC 4 application which is running on a Windows 2012 R2 with IIS 8.5 machine. There is a wierd behavior which I cannot figure it out. The cache seems is clearing itself. By cache, I mean MemoryCache.Default, HttpContext.Current.Cache, and also OutputCache. I'm googling the issue for hours and seems nothing is wrong. Can you list cause of clearing cache? I mean is there a checklist which I can test the server against it? Thanks in advance.
Those caches are held in memory, and as such are volatile. They are held against the W3wp process that IIS spawns to handle those requests.
After a period of inactivity, IIS closes down the processes, so these caches will be cleared.
IIS also closes down the processes (recycles the app pool)
By default after 1746 mins (IIRC)
After the memory used by a thread reaches a set threshold
Caches are also isolated by thread, so if you have a web farm/web garden, these caches are not shared, again IIRC
If you need to persist these items longer, then you will need to look at caching the objects in a persisted storage area, such as a db or application state managed server.

Forms Authentication & ASP.NET Membership Session Timeout

I have a website which has Forms Authentication and ASP.NET Membership is used in it. At some pages Transactions (System.Transactions) are used too.
After deploying it to the server, the session timeout issue is creating a mess, and few E-mail relays and DB operations are unable to be executed.
I want to know how can I fix this issue. If additional information is needed I can provide.
I have looked into too many blogs and forums, but could not find the solution or the correct/single solution.
Following error is shown sometimes:-
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool.
And the application is deployed on Windows 2008 R2 Server with IIS 7.5.
Looking forward for quick response.
Sounds like you're not closing your DB connections correctly.
Make sure any place you open a SQL connection that you're closing it. Ideally wrap them in using blocks.
Post up some some of your typical DB code and I'll review it.

Categories

Resources