Application should not be Expire time in ASP.net (using this FormsAuthenticationTicket )

K

karunakar

Hi All


I dont want to expire the applicatoion
Once login the application i dont want to expire the application
Presently iam doing using cookies this is not working fine
Please help me out

I was doing like that

System.Web.HttpCookie c = new System.Web.HttpCookie("EXPIREANONYMOUSUSER",
"EXPIRE");
c.Expires = DateTime.Now.AddMonths(6);
Response.Cookies.Add(c);


here "c.Expire" is expiration time

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
txtUserName.Text,
System.DateTime.Now,
c.Expires,
// This is my exprition duration
false,
txtPassword.Text,
FormsAuthentication.FormsCookiePath);


Regards
Karunakara Rao
 
G

Guest

Hi Karunakar,

I have a solution for this. The idea of my solution is simple, session will
timeout only when there are no more requests from that particular user. What
we can do is continously ping the webserver at equal intervals. Let's say you
have your web application's time out set as 20 mins. We will ping the
webserver every 15mins. For this I am using the xmlHTTP object to ping the
webserver.

To implement this
Step 1: Create a dummy page pingreceiver.aspx on the server

Step 2: In the HTML portion of the page copy the following javascript code
Ofcourse, you can move the following code into any script file also and
include that script file in the html portion of the file.

var m_nTimetocheck = 15 * 60000; //This variable defines the period when the
client application has to ping the server.
var m_nTimerID; // A variable to hold the timer handle
var oxmlhttp; // An object to hold the XMLHTTP object.

function onSessionCheck()
{
//Creating an instance of the xmlhttp object.
oxmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

//Initializing the callback method which should be called.
oxmlhttp.onreadystatechange = onSessionCheckReceiver;

//Retrieving the required file
oxmlhttp.Open("GET","pingreceiver.aspx",true);

//Initiating the request
oxmlhttp.send();
}

function onSessionCheckReceiver()
{
if (oxmlhttp.readyState == 4) //if request has be processed
{
//No code for this example
}
}

m_nTimerID = window.setInterval("onSessionCheck();",m_nTimetocheck);


Step 3: Run the application. You will notice that the application is not
expiring even though there is no activity on the website.

Let me know if this code has been useful for you..


thanks & regards
Saidevakumar
 
L

Lau Lei Cheong

Another possible way would be to have another blank aspx page within
<iframe> periodically refresh itself let's say, 5 minutes.

This will ensure the server won't wipe your user's session. The page will
not flicker because it's within iframe, and the response should be quick
because the aspx page request and response virtually contains nothing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top