Can anyone tell me why the session clears itself automatically after a certain amount of time in my application?
I use the following line to create a session variable to pass data between classes:
string data = TextBox.Text
Session["Data"] = data;
After around 10 - 15 minutes i refresh the page to find that the session cache has been cleared and my application collapses on itself.
Is there a way to extend the session time in web.config?
Im not fully aware of how powerful Session's can be so any help would be great guys thanks
Look in your web.config file and see the sessionState section:
<configuration>
<system.web>
<sessionState timeout="30"></sessionState>
</system.web>
</configuration>
I have changed it to 30 to extend the Sessions life for an additional 15minutes. You can change this to suit your requirements.
Related
I am changing session state in:
<sessionState cookieName="myCookieName" />
It changed correctly, but one issue I am facing is default the "ASP.NET_SessionId" is also showing.
I didn't understand what I am going wrong. How can I fix this?
<system.web>
<sessionState cookieName="foo" />
</system.web>
I need only to show a cookie named foo. I don't want to show "ASP.NET_SessionId".
Maybe it's just a cache issue. Try to delete the cookie in the browser.
Then log in again, and see if it appears again...
I am creating a mvc4 application and here I am creating a cookie to give a user access to various pages depending on their roles and things. but I have different doubt. Instead of logging off people generally tend to close the browser window. So, I made the cookie not store any of the data from the login when that happens (or I think thats what happens, according to the blogs and answers Ive read so far!)
I only want 10 users to access that site at one time. So when the user closes the browser or when the session ends I want it to execute the LogOff function that keeps track of the number of people logged in and opens up that port session for use by someone else.
I tried adding session_end in the global.asax page and it just never seems to get there. and for testing purposes I had it expiring in a minutes time. But it does however go to the Session_start in the same global.asax page.
Any idea as to how I can get this to work?
This is what I had to do (hoping its not silly!):
In the web.config, needed to add the timeout here to trigger session_end
<system.web>
<sessionState mode ="InProc" timeout="10"/>
</system.web>
Although, in the same web.config there is a timeout here, i dont know where it goes.
<authentication mode="Forms">
<forms loginUrl="/SiteUsers/Logon" timeout="10" />
</authentication>
If you guys have other ways to get around this, please do tell me, im all ears! Im still in the trying and testing everything phase so any help will be much appreciated :)
Thanks guys! hope this helps solve someones problem.
This article shows how to implement sesstionState inside web.config file. But what I want to do is to clear the session when user is idle for 15 minutes or higher. And reset the time when the user is active within the scope of time. Is this possible? If not how could I do this without using any javascript code/jQuery?
BTW, I have my BaseController where all Controllers inherits to it. Hope someone could give me the better idea.
Use the timeout property in the <sessionState> configuration section.
<sessionState
...
timeout="number of minutes"
...
</sessionState>
Documentation:
http://msdn.microsoft.com/en-us/library/h6bb9cz9%28v=vs.100%29.aspx
I have an aspx page with a few textboxes and a submit button.
Once the submit button is clicked an xml file is created from the table/textboxes on the screen.
That works fine if doing it right away but if you click the button after 20 mins or so the page errors out.
I have:
<location path="Default.aspx">
<system.web>
<httpRuntime executionTimeout="1000000000"/>
</system.web>
</location>
in web.config and <asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="1000000000" /> on the aspx page but it still times out after around 20 mins or so.
What am I missing?
Default session time is 20mins Msdn
Here is one of the way
1.http://weblogs.asp.net/stevewellens/archive/2009/06/09/ah-ah-ah-ah-staying-alive-staying-alive.aspx
Check this Solution
2.how to avoid session timeout in web.config
3.https://stackoverflow.com/a/412502/1053241
In your web.config you more than likely have
<sessionState timeout="20"></sessionState>
You shouldn't really extend your session timeout beyond this though
How to set session timeout more than 20 min.?
This post explains all the relevant places to check your session timeout
Also when you come to deploy your application remember to check the IIS timeout configuration
Maybe the Session is over, Try to set the SessionTimeOut, or write a JavaScript function to send an AJAX request time by time to keep the Session alive.
But I really don't think you're on the right way with that, if the Session is over you should redirect to the login page.
Here is a good example to keep a session alive: http://www.dotnetcurry.com/ShowArticle.aspx?ID=453
Also rather than extending your session you could just warn the users that they are about to be timed out of the system and ask them if you wish to continue using the site
http://programmerramblings.blogspot.co.uk/2011/07/aspnet-session-timeout-control-with.html
This control lets you do that
I am setting this at individual page and button click event. Seems to do the trick if you do not want a application wide timeout change in config.
HttpContext.Current.Server.ScriptTimeout = 90000;
got a problem with my asp.net mvc project timing out after only a couple of minutes. It's especially annoying because I've got quite a complex upload and import procedure which falls over when i get logged out. I currently use asp.net membership provider for authentication.
I've tried a few things that I've seen on this site and others but to no avail. Here is what I have so far in the web config:
<location path="Admin/Upload">
<system.web>
<httpRuntime executionTimeout="1200"/>
</system.web>
</location>
<system.web>
<sessionState mode="InProc" timeout="20" cookieless="false" />
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="20" />
</authentication>
<add name="ConnectionString" providerName="System.Data.SqlClient" connectionString="Server=SERVERNAME;Database=DBNAME;User Id=USER;Password=PASSWORD;timeout=30;MultipleActiveResultSets=True" />
I was sure it was only a minute before being timed out before I added the sessionstate timeout, then it was upped to 2 mins, but can't be 100%.
I thought about using this:
<lifetime leaseTime="15M"/>
...but not 100% sure how to implement it - anyone had any success with it, or know something else I could try?
Thanks
EDIT: I'm on a cloud hosting solution, but only have a control panel - no access to IIS
UPDATE: I've now tried adding lifetime leasetime and it's not made any difference:
<system.runtime.remoting>
<application>
<lifetime leaseTime="20M" />
</application>
</system.runtime.remoting>
</configuration>
UPDATE 2:
Ok, I've edited the title and the web config values to reflect my latest effort, but I'm still struggling. I spoke to the hosting company who set the connection timeout to 20 minutes. However, it the session ends after 10 mins. Is there anything else I can try?
I'm getting there, but I would like 20 minutes!
The lifetime leasetime tag goes in the application tag.
<application>
<lifetime leasetime = "15M"/>
I've never actually used it but if it is like other timeouts idk if you will need the M at the end. That is pure speculation though. You should also be able to set it to "0" so that its lifetime is "forever"
As for the session timeout that looks like it should be set for 100 minutes. However, it should be inside of your <configuration> tags
EDIT
Completely unrelated to the question kind of. But i like how your runtime execution timeout is "over 9000"
Right, I got a solution to this, but it wasn't what I was expecting.
It turned out I was using the aspnet Membership Provider wrongly. I was using like a previous membership system I worked on and logging in then setting the UserId as a session variable and using that throughout the site. I then discovered that is the incorrect way to use it, and changed it to a combination of User.Identity.IsAuthenticated and Membership.GetUser().ProviderUserKey.
It no longer times out and all is well. Thanks anyway.