In my webapplication, I have set a timeout for the session so that if the user stays inactive for more an hour, they will be logged out.
this is set in the startup.auth.cs file and works perfectly running locally thanks to the Nuget packages of Windows.Owin...
Though, after publishing the project and putting it on the webserver, the timeout is suddenly set to 20 minutes instead of the 1 hour I had initially set and thus this forces users out of my application after 20 minutes because it takes some default setting.
when searching through my published files, I can no longer find the startup.auth.cs
nor can I find anything connected to it or even something that looks like it.
how do I change this? how do I include my startup.auth.cs into the publish or do something so that the session stays open for the complete hour that I requested instead of the default 20 minutes.
the file "startup.auth.cs" is included in the project so it's not like it should be ignoring it when running the publish.
unfortunately I can not show you any code today; it is confidential.
fortunately I should not have to show code for this question.
Change the session state configuration in Web.config (Default: 20 minutes)
<sessionState timeout="120">
And is IIS you can change idle timeout value
IIS Manager > Application Pools > DefaultAppPool > Properties > Performance
Go to this form and you can change the session timeout as per your requirement
Related
I started seeing errors in a .Net MVC web app hosted on Appharbor whilst a background thread was running - after careful analysis - I can't work out the cause.
Firstly, the exception I noticed is a ThreadAbortException.
However, this is really just signifying that the thread is being killed. Before the thread is killed, you can see a new worker is created by IIS and Application_Start is called on the same machine. Once the new application is up and running, IIS kills the old app and new requests are handled as expected.
At the same time, IIS logs a message of:
ShutDown Message: IIS configuration change
HostingEnvironment initiated shutdown
HostingEnvironment caused shutdown
ShutDown Stack: at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at System.Web.Hosting.HostingEnvironment.InitiateShutdownInternal()
at System.Web.Hosting.HostingEnvironment.InitiateShutdownWithoutDemand()
at System.Web.Hosting.PipelineRuntime.StopProcessing()
In .Net Health Monitor Logging you get a:
Message: Application is shutting down. Reason: Configuration changed.
Event Detail Code: 50004
A quick google reveals the source code I suspect is the reason for the error:
if (!HostingEnvironment.StopListeningWasCalled && !HostingEnvironment.ShutdownInitiated) {
// If GL_STOP_LISTENING wasn't triggered, the reset is likely due to a configuration change.
HttpRuntime.SetShutdownReason(ApplicationShutdownReason.ConfigurationChange, "IIS configuration change");
}
source: https://github.com/Microsoft/referencesource/blob/master/System.Web/Hosting/IPipelineRuntime.cs
My first thought was to check timestamps for file changes, both in the bin folder and the main application directory - however, this error is thrown without any file changes. Given it only happens on Appharbor, I can't attach to the process and debug that way. I've also monitored memory usage, and don't see any issues there.
The source code states:
If GL_STOP_LISTENING wasn't triggered, the reset is likely due to a
configuration change.
Hence, what else could be causing the error and application recycle, if the web.config / other config files aren't changing?
There are many reasons, which are listed by this helpful blog entry.
Application pool settings
The processModel element of machine.config
Memory limit
Request limit
Timeout
IIS configuration change should happen when something (anything) changes in your IIS application configuration or code. Examples:
Change in web.confg
Change in any dll, aspx, etc...
In any of those cases, IIS application will recycle. In addition, IIS will recycle your process every 29 hours by default, but that will probably not be called "IIS configuration change"
It looks like this was a Microsoft bug.
Unexpected ASP.Net application shutdown after many App_Data file
changes occur on a server that is running Windows Server 2012 R2
Hotfix: https://support.microsoft.com/en-us/kb/3052480
Last Review: 09/08/2015 16:29:00
Once this hotfix was applied, the errors went away!
I am writing a program recording service calls and treatment done. We have a number of users who open and close calls and I want to show at all times the total number of calls opened today and the total number closed today and the difference between them. I thought of doing it with an application variable. I have to reset these variables to 0 every day. Where would I do that? I thought in the Global.asax but in which event could that be done? The application is running all the time so I suppose Application_Start wouldn't be appropriate. So where? Thank you.
You could configure the Periodic Restart Settings for Application Pool Recycling in IIS:
The element contains configuration settings that allow you to control when an application pool is recycled. You can specify that Internet Information Services (IIS) 7 recycle the application pool after a time interval (in minutes) or at a specific time each day. You can also configure IIS to base the recycle on the amount of virtual memory or physical memory that the worker process in the application pool is using or configure IIS to recycle the application pool after the worker process has processed a specific number of requests.
But this has a side-effect of putting the application offline during the time the pool is restarting, so if you have any user connected at that time it will lose its session. This can be minimized by restarting the application at a time you have no users connected, like at dawn.
The following config snippet set the application pool to daily recycle at 3:00 A.M.:
<add name="Example">
<recycling logEventOnRecycle="Schedule">
<periodicRestart>
<schedule>
<clear />
<add value="03:00:00" />
</schedule>
</periodicRestart>
</recycling>
<processModel identityType="NetworkService" shutdownTimeLimit="00:00:30" startupTimeLimit="00:00:30" />
</add>
I'd have a date variable with the last time the counter was reset, and check the date is "today" on every access to the counter.
Unless you have critical performance problems, I guess that'd be the way to go.
Sample easy-lazy code to call whenever you are updating the counter:
lock(myCounter)
{
if(DateTime.Now.Date != lastDateCounterWasReset)
{
lastDateCounterWasReset = DateTime.Now.Date;
myCounter = 0;
}
myCounter++;
}
Now we'd need to know more about how you'd like to be storing those variables (myCounter and lastDateCounterWasReset), but could be basically anywhere (database, filesystem, etc.)
I would store the calls to a database and do a select which groups by the current day to get the total calls, etc. for display.
That way it will automatically reset for you when a new day starts, and you don't need to worry about IIS Resets destroying your in memory data.
If you don't want the performance hit of querying too often, there are a number of caching options available.
I suppose you could use the Application_BeginRequest method. Use a boolean to see if it's already run that day.
Another option is a scheduler with a hidden URL to reset.
My situation is this:
was created a page that will run a long process . ... This process consists in:
- Read a file. Csv, for each row of the file wil be created an invoice...in the end of this process shows a successful message.
for this it was decided to use an updatepanel so that the process is asynchronous and can display an UpdateProgress while waiting to finish the process ... for this in the property of scriptmanagment was added the AsyncPostBackTimeout = 7200 (2 hours) and also timeout was increased in the web.config of the app as in qa and production servers.
Tests were made in the localhost as a qa server and works very well, the problem arises when testing the functionality on the production server.
that makes:
file is loaded and starts the process ... during this period is running the UpdateProgress but is only taking between 1 or 2 min and ends the execution without displaying the last message, as if truncated the process. When reviewing the invoices created are creating only the top 10 records of the file.(from a file with 50,100 or + rows)
so I would like to help me with this, because i don't know what could be wrong.
asp.net is not suited for long running processes.
The default page timeout for IIS is 110 seconds (90 for .net 1.0). You can increase this, but it is not recommended.
If you must do it, here is the setting:
<system.web>
...
<httpRuntime executionTimeout="180"/>
...
<\system.web>
Refer httpRuntime
Pass on this work to a windows service, WCF or a stand alone exe.
Use your page to get the status of the process from that application.
Here is an example that shows how to use workflows for long running processes.
You move the bulk of the processing out of asp.net, and free its threads to handle page requests.
Some quick details:
I'm running ASP.NET 4.0.30319.0 on IIS6. I've been hosting a website that contains a ReportViewer for quite some time now (~3 years). In April, I upgraded to the 4.0 runtime, and things ran smoothly for a couple of months.
Now, I'm suddenly starting to see quite a Session Timeout exceptions occur on the pages hosting the ReportViewer. The Event Viewer has many many of these events logged, and it's rather hit or miss when it comes to actually being able to view the page. Hitting the page once, you can see the generated report. Refresh, and the error occurs. Refresh again and it returns...
I've scoured many forums trying to figure out the issue - most seem to recommend changing SQL server settings (which I'm not using), changing the AsyncRendering="False", changing the Application Pool settings, or the timeout. I'm reluctant to change any of these, as it has worked only a week ago, without this issue.
Short of a Windows Update, or someone making a change to the server without my knowledge, I'm out of ideas...
Update
I've tried increasing the maximum virtual memory, in the app pool, which didn't work.
I have almost the same problem, after upgrading to .NET 4.0 and Report Viewer 2010. I did both upgrades at the same time, now I'm not sure who's to blame. In my case, refresh does work, but the users keep the page open during the night, then click on refresh the next morning, when the session is already lost. Our app pool recycles every night.
I believe the report viewer is supposed to keep the session alive, but it doesn't. There's no request of any kind from the report viewer. It then loses it's stored state when the session ends, either by session expiration or app recycling. I'm also using InProc, I tried to change it, but the report viewer did not work with State Server. I will try again at a later time, to move away from InProc.
See my similar question.
I haven't put it into production yet, but I gave the aspx pages with the reports a custom page to derive from, and I will check there if the session has actually timed out. It basically reloads the report page, instead of doing postback where it expects the session.
if (Context.Session != null)
{
//Tested and the IsNewSession is more advanced then simply checking if
// a cookie is present, it does take into account a session timeout, because
// I tested a timeout and it did show as a new session
if (Session.IsNewSession)
{
// If it says it is a new session, but an existing cookie exists, then it must
// have timed out (can't use the cookie collection because even on first
// request it already contains the cookie (request and response
// seem to share the collection)
string cookieHeader = Request.Headers["Cookie"];
if ((null != cookieHeader) && (cookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
{
Response.Redirect(Request.Url.ToString());
}
}
}
I am using a console application to call web service methods and I am stepping through the code using the debugger in vs2008.
Sometimes I need to stop and think about things, and compare values. Not talking hours, just a few minutes, at this point the web service times out, how can I avoid this, so that the web service does not time out at all.
Thank you
Ok, now a serious answer, found at:
http://bytes.com/groups/net-web-services/628561-increase-default-webservice-timeout-globally
Increase the Timeout property of the web-service-proxy.
MyWebServ obj = new MyWebServ();
obj.Timeout = -1; // -1 for forever otherwise in milliseconds
Increase the timeout value in http-runtime tag in web-config of ASP.NET
project./app.config if the web consumer application is Windows.
Increase the timeout value in http-runtime tag in web-config of Web Services
project.
You can turn the timeout off by stopping the application pool from recycling:
In the IIS console, go to the app pool properties and set "Ping Enabled" to false
(hope this helps! - is my first answer on here)
I hade the same Problem and in my case the Solutions mentioned here did not really help.
After long searching time i found the solution somewhere else, i had to disable worker process pinging for an Application pool by following command:
appcmd set apppool /apppool.name: string /processModel.pingingEnabled: false
alternativly you can configure this in the User Interface by:
Open IIS Manager
On the Connections pane, expand the server node and click Application Pools.
On the Application Pools page, select the application pool and then click Advanced Settings in the Actions pane.
For the Pinging Enabled property, select False to disable pinging, and then click OK.