IIS ASP.NET Session is lost - c#

I know that this has been asked several times, but in the web config we set the
<sessionState timeout="2880"></sessionState>
the app pool recycle is 1740 minutes, the application pool timeout is also 1740 mins now,
ping and rapid fail protection is turned off, and in the global.asax we log every application start, session start/end, application error.
I see 2 "application start" than 2 "session start" in the logs, nothing changes, a few minutes later, we get a new "application start" (2 of them again) with 2 "session start"-s, with the same sessionid as before (no "session end" in between). The result is a web application that quits every few minutes.

Not sure about this, but how many instance of the application do you allow?
Under IIS>Application Pools>YourAppPool>Advanced Settings;
you'll find relevant settings:
idle time-out (set to 0?)
Disable Overlapped Recycle (this might be your culprit;a new instance starts before the old one is disposed?)
Another thing i can think of is 'Service Throttling' on your binding, or perhaps there are multiple Sessions or Instances allowed?

Related

Net Core 3.1 IHttpClientFactory/HttpClient Slow on First Request

I have a .Net Core 3.1 app. In the app, I use the IHttpClientFactory to create an HttpClient. When I make a call using SendAsync, the first request takes over 2 seconds whereas subsequent requests take less than 100 ms. This is not acceptable performance for a production application.
I have also noticed that it happens if I don't make any requests for a while. I came across the PooledConnectionIdleTimeout property, which defaults to 2 minutes, and I can extend that time, but that would only work for pooled connections that already exist, not when needing to create a new one.
I configure the HttpClient in my Startup.cs as such:
services.AddHttpClient("HttpClient",
h =>
{
h.BaseAddress = new Uri(Configuration["PythonUrl"]);
});
Use the HttpClient like this:
var client = httpClientFactory.CreateClient("HttpClient");
var res = await client.GetAsync(nameof(Accounts).ToLower() + "/" + id.ToString() + "/");
when the "Configuration["PythonUrl"]" contains PC name,like this :
{
"AllowedHosts": "*",
"PythonUrl": "http://PC202003261059:8000/",
"url": "http://*:5000"
}
The HttpClient's first request becomes very slow. Can anything be done to avoid this?
I had a similar problem and found a solution that works well for me.
Note that this solution will only work for IIS hosted WebApps.
When hosting an application in IIS, the AppPool is responsible for actually running it. However, it only starts the application when it receives the first request. This is fine in most situations and is therefore the default setting, but this leads to a slow first request.
In IIS manager, right click on the Application Pool that runs your
app and select 'Advanced Settings'. Set 'Start Mode' to 'Always
Running'.
Rick-Click your Site and under 'Manage Website' select 'Advanced
Settings'. Set 'Preload Enabled' to 'true'.
This should make the first request faster and won't put your AppPool to sleep after some time. It should also be noted that this may impact the performance of other apps hosted on the same server.
This article helped me with this.
Disclaimer: the first request might still be slower due to several reason (some of which may be client-side like DNS requests, or network-related lost packets, poor internet connection etc...).

Session variable lost in webapplication

I have a problem with Session Timeout in my WebApplication project.
I set session timeout in web.config to 1440 minutes.
but it does not work...
How can i solve it?
try setting the timeout also in your application pool, on the Process Model tab--> idle Time-out.

Apparent delay in Azure KeyVault access

We have an Azure-based ASP.NET Web Service that accesses an Azure KeyVault. We are seeing two instances in which a method "hangs" on a first try, and then works a minute or so later.
In both instances, a KeyVault access occurs. In both instances the problem started when we started using the KeyVault in these methods.
We have done very careful logging in the first instance, and cannot see anything else in our code that could cause the hang. The KeyVault access is the primary suspect.
In addition, if we run the app from our local servers (from Visual Studio), the KeyVault access works fine on the "first try". It only produces the "hang" error when it runs in production on Azure, and only on that "first try".
By "hang" I mean that in one instance, which is triggered by an external API, it takes at least 60 seconds (we can tell that because the external API times out.) In the other instance, which is triggered by a page request, several minutes can pass and the page just spins, at which point we assume the DB request or something else has timed out.
When I say "a minute or so later", that's as fast as we have timed the retry.
Is there some kind of issue or function where the KeyVault needs to be "warmed up" before it works on the first try?
Update: I'm looking at the code more carefully, and I see at least a couple of places where we can insert still more logging to get a more exact picture of where the failure occurs. I'm going to do that, and then I'll report back here.
Update: See answer below - major newbie error, has been corrected.
Found the problem, and the solution.
Key Vault access needs to be called from an async task, because there is a multi-second delay.
private async Task<string> GetKeyVaultSecretValue(varSecretParms) {
I don't understand the underlying technology, however, apparently, if the call is from within a standard code sequence, the server doesn't like to wait, and so the thread is abandoned/halts.
According to your description, it seems that it dues to WebApp that does not enable Always on .
By default, web apps are unloaded if they are idle for some period of time. This lets the system conserve resources. In Basic or Standard mode, you can enable Always On to keep the app loaded all the time
If possible, please have a try to enable Always on and try it again.

IIS pool duplicates after appdomain restart

We have an application which read messages from IBM MQ Topic and interact with users via SignalR WebSockets.
Case:
Open iis asp.net application web.config
Change and save it (this causing appdomain restart)
Repeate step 2 10 times
After that we can see many Application_Start/Dispose events in logs but at ONE of appdomain restart iterations haven't Dispose call. Cause that out IBM MQ listener handling message from old AppDomain therefore we have duplicate handling and business errors.
It seems like something constraint AppDomain from unload.
I know what it's very hard to say what's there happening, but maybe anybody knows how can we trace that problem.
Disable Overlapped Recycle is true
Shutdown Time Limit is 3s
what I have do in similar situation - on global.asax use this call
void Application_End(object sender, EventArgs e)
{
// here signaling the listener to close - and wait until they do
// also raise the shutdown time limit to more than 3 seconds, give them time to close
}

My ASP.NET web service on localhost is timing out too quickly

So here I am, trying to debug a little problem in my ASP.NET web service on localhost, and while I am stepping through it, the darned thing times out. Here I thought the default timeout value was 20 minutes. But the timeout appears to happen at 30 seconds -- I've timed it twice -- although it was 20 seconds in another timing I did.
I've tried to govern this by setting sessionState timeout to 30, in accordance with what MSDN says about HttpSessionState HERE. With this code:
<sessionState
mode="InProc"
cookieless="true"
timeout="30" />
in .
MSDN says the value of the timeout is supposed to be in minutes ("Gets and sets the amount of time, in minutes..."), but it doesn't really seem to make any difference what it's set to. Machine.config does not specify any value, so it should default to 20 minutes.
I am running in IIS 7.5. I checked the properties of the ASP.NET Session State Mode Settings in IIS, and it is selected as "In process". I don't know how this affects things, if it does.
So this is a mystery to me.
If your client is timing out when calling a web service take a look at-
http://msdn.microsoft.com/en-us/library/system.web.services.protocols.webclientprotocol.timeout.aspx

Categories

Resources