Session sometimes timesout too quick - c#

I am noticing session timeouts on my asp.net mvc web app randomly without browser being incative for for more than few minutes.
My understanding is the default timeout should be 20mins. But sometimes I get a timeout in couple minutes or even less than that. For example after browsing on the site for a while I might get a session timeout when i refresh a page very soon after I enter the page.
This is very random but I have seen this happen quite a few times now and I am not sure how I can trace this to see why I loose sessions every once in a while whithout browser being inactive long.
I checked my web.config an no timeout value is defined there so I assume it should be 20mins.
Hard to debug as this does not occur regularly..

There's an IIS setting for timeout. check it also
Maybe your application calls session abandon?
You can register session end handler to write to log on the server, to see exactly when this happens.

IIS overrides your web.config.
Go into IIS (this is for IIS 6)
Right click your website, properties, asp.net tab.
Click Edit Configurtation button on bottom, ASP.Net Configuration Settings, State Management, set your timeout here.

Are you creating any files in the bin folder, that can also cause the application to restart.
There are a number of other causes too, try googling .....
causes for asp.net web application to restart
I got a couple of hits that list the possible causes.

Related

Sys.WebForms.PageRequestManagerServerErrorException / HTTP1.1 Internal Server Error

I've perused the forums for a couple weeks now trying out different solutions, but nothing seems to be helping. Here's my problem:
I have created an ASP.NET Web Application for displaying dashboard-style metrics in a Service Desk setting. The client has large screens in the service desk room that display specific pages of my web app.
Some pages use UpdatePanel, others use $.ajax to make calls to code behind every 15 seconds (I have various [WebMethod]'s set up for the ajax calls).
These dashboards work fantastic for about a day, maybe 2, then they stop refreshing, and the above error message can be found in the console. Bug checking for the ajax methods show they hit the 'error:' portion of the ajax call.
Below are solutions I have tried to no avail:
Added EnableSessionState="False" to the <%# Page %> header.
Added validateRequest="false" to the <%# Page %> header.
Added enableEventValidation="false" to the <%# Page %> header.
Added try-catch statements to my web methods to catch the error.
Added Global.asax and overrode the Application_Error. Made it write to an application event log. Example below.
Exception exc = Server.GetLastError().GetBaseException();
if (!EventLog.SourceExists("Dashboards"))
{
EventLog.CreateEventSource("Dashboards", "Dashboard");
}
EventLog log = new EventLog();
log.Source = "Dashboards";
log.WriteEntry(exc.ToString());
Server.ClearError();
This Global.asax exception is never called (as far as I can tell) and I never have any exceptions logged.
I can't think of any other troubleshooting to do with this.
If I had to guess, I would say it's the every 15 second ajax/updatepanel calls that is causing the issue. The app is running on IIS v8 on Server 2012. Perhaps IIS thinks it's getting DDOS'd or something similar? Another possibility is that I have various threads running in the code behind (aspx.cs) updating information that the ajax call then pulls from. Maybe the thread is getting killed somehow?
I am currently out of ideas. Any help with troubleshooting would be appreciated. I'm more than happy to upload more code as example as well.
Thank you to anyone who can assist with this.
I managed to solve this issue after extensive research.
These web pages are naturally long-running (they are dashboards that are displayed and updated continuously in a service desk environment) and they have various long-running threads that perform operations in the background.
IIS has functionality to recycle application pools, and by default the interval is set to 29 hours, which coincidentally was the interval of the internal server errors.
Since this is the only application running on this server, and there are a select few computers that will be accessing this website, I disabled the application pool recycle. This immediately fixed the problem.
I will be checking the server on a regular basis to make sure this change does not cause any other adverse issues, but so far so good.
Hopefully this helps anyone else having this issue with long running web applications.

Code Build logs me out of application (IIS)

I have a peculiar problem that just started happening out of the blue.
I will build my application using an IDE, navigate to it in the web browser, and log in.
Log in uses FormsAuthentication to set a cookie.
I then found a bug so I fixed it and rebuild my application.
When i refresh the page I navigated to, it had logged me out of the application and ask to log back in again. (clears my cache or something . . . not sure, HELP!!)
Why is this happening, it never happened before and all of a sudden it started happening.
The application is hosted though IIS 7.
So solved my problem by setting Session Sate Mode Settings and using the State Server option. Just default settings did it for me.

How to deploy an MVC application on IIS 7?

I have a MVC application and I can't get it working on IIS 7. Debugging in VS2010 works fine, but when I publish the website to my local IIS7, I see nothing but blank pages.
Here is what I have done:
On the project, right click and click Publish. In the Publish Web window I set these settings:
Publish method: Web deploy
Service URL: localhost
Site/application: Default Web Sit\Africa
both, Mark as IIS application on destination and Leave extra files on destination (do not delete are checked.
In IIS, my application runs under a application pool with supports .net 4.0 and managed pipeline is set to integrated.
I don't get any error while publishing, but when I navigate to my site I only see blank pages. Nothing happens.
What goes wrong?
EDIT:
When I navigate to http://localhost/Africa/ I see a blank page. When I navigate to http://localhost/Africa/Views/Home/ I get a 500 error.
How can I solve this?
I ran in to the same exact problem, it took quite a bit of digging to solve.
I finally found the solution to it on this page: Getting an ASP.MVC2/VS2010 application to work in IIS 7.5
Yeah, I know that this is an old thread but for the sake of saving someone else's time I'm adding this. Also make sure you have HTTP Errors, HTTP Redirection, and Static Content enabled in IIS.
In your application pool advanced settings, make sure you have Enable 32-bit applications set to true.
Some other things to try:
Change the application pool to classic.
Make sure you have the correct version of MVC installed on your server.
If you are getting 500 errors, you can turn on Failed Request Tracing and check the logs. If you are getting 500 errors and no logs are being created, you need to check your web.config.
Blank page normally doesn't necessary mean it's not working, if you default page doesn't have anything, it will be blank.
If you run into some error, you normally will see an error page.

How to debug in production envirnment for ASP.NET web site?

Our client recently complains that when they work on our production server, the user menu switch randomly, but this happens only occasionally .
The application has two types of user menu: regular user and restricted user. The target browser is IE. It's a ASP.NET3.5 application written in C#.
We can never reproduce this issue in our local environment. So it is very difficult to debug it.
Anybody met this type of issue or any clue how to debug it?
Web App Logging
Have you looked into adding a variable to your web.config to have your application perfrom less or more logging. I've done this in the past to track down bugs.
Client-side Logging
Perhaps not the intended use, but http://www.clicktale.com/ provides a javascript site analytics tools that can record all user mouse/keyboard activity that you could correlate to the web app logs. However it cost $$$.
Log Messages. Log them all over that has anything to do with the menu. Then the next time the user reports seeing it look at the log message.
Does the production environment use any load balancing s/w? Perhaps there is a problem with some session scope variables.

How to investigate why Session() expired and let users know

How to investigate what is causing Session expiry?
I would like to give some advise to end-users who have the following problem with our website:
If Session("xxxx") Is Nothing Then say something.. WHY??
Can I add something to web.config to make sessions last longer or should I read the IIS log files to see why this happens?
First session's are configured in web.config's <sessionState> element.
Also you can pick up session ending event (SessionStateModule.End) but note (1) this only works for in-process session management, and (2) you will need to record (in the session) when requests occur, so you can determine if it was a timeout or some other reason.
I think normally if a user does nothing for a period of time(no page refreshes etc) then the session will expire, otherwise it would just consume loads of resources on the server.
In classic asp there was a timeout you could set, not sure if its still there in asp.net or not.
If you don't want the session to expire while to user is looking at your site you could maybe put a meta refresh into your pages, or be a bit cleverer and use some kind of ajax timer that triggers and does a partial refresh on something
You could put some code in your Global.asax file's Session_End method to help determine what went wrong, assuming you're running your session as InProc.
To increase your session length in IIS6, do the following:
Open IIS
Right-Click your website and choose properties
Choose the Home Directory tab
Click the Configuration button, in the Application Settings section
Choose the Options tab
Increase the Session Timeout value to whatever you want.
Close everything and do and IISReset

Categories