470,641 Members | 1,587 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,641 developers. It's quick & easy.

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

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

Nov 19 '05 #1
2 1928
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_nTimetoch eck);
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

"karunakar" wrote:
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

Nov 19 '05 #2
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.

"saidevakumar" <sa**********@discussions.microsoft.com> bl
news:EA**********************************@microsof t.com g...
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_nTimetoch eck);
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

"karunakar" wrote:
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

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by David Graham | last post: by
7 posts views Thread by What-a-Tool | last post: by
1 post views Thread by Grey | last post: by
2 posts views Thread by Dicky Cheng | last post: by
1 post views Thread by Polani | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.