Click here to Skip to main content
15,890,932 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i am using asp.net and sql server for my web application.
my files are published in a shared windows hosting server,the default session length overridden by web hosting service 5 mins.
for that i decide to use cookie instead of session.

now the problem is...if i use a page after 3 mins its going to the custom error page named "sessionexpire.html".....i can not understand the problem...actually what is going on...please help me....

What I have tried:

C#
private void CheckCookie()
{
HttpCookie CookieName = Request.Cookies["MyCookie"];
CookieName.Expires = DateTime.Now.AddMinutes(30);
if (CookieName != null)
{
Uid = Request.Cookies["MyCookie"]["UserId"];
UTyp = Request.Cookies["MyCookie"]["UserType"];
UName = Request.Cookies["MyCookie"]["name"];
ArrangerId = Request.Cookies["MyCookie"]["ArrangerId"];
}
}


C#
protected void Page_Load(object sender, EventArgs e)
{
try
{
CheckCookie();
}
catch (Exception ex)
{
string s = ex.Message;
Response.Redirect("logout");
}
}



and in web config i have written

sessionState mode="InProc" timeout="30"
compilation debug="true" and targetFramework="4.0"
customErrors mode="On"
defaultRedirect="sessionexpire.html"
authentication mode="Forms"
and forms timeout="30"
Posted
Updated 18-Mar-16 23:31pm

1 solution

Check your times: remember that the cookie is client based, so any expiration time will be relative to the local time on the client, while you are setting the expiration time relative to the local time on the server. If they are different by a couple of minutes that could cause the expiry. Or as is more likely, the server is in a different timezone completely, and the expiry time you select has already passed for the client!

So start by looking at the cookie - use Chrome and you can inspect cookies quite easily in "Settings" and the other browsers should be fairly simple as well - or write the expiry time to your page when you set the cookie and look at it in the browser window for a manual comparison.

And if your hosting service is overriding the default session timeout, then don't add override code to your configuration - it give the misleading impression of the session length which will probably come back to bite you later when you have forgotten why it doesn't actually work... :laugh:
 
Share this answer
 
Comments
BIBASWAN 19-Mar-16 9:28am    
protected void btnSubmitQ_Click(object sender, EventArgs e)
{
try
{
Connection cn = new Connection();
SqlCommand cmd = new SqlCommand("[usp_SubmitQuery]", cn.ClsConnection);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter Da = new SqlDataAdapter(cmd);
cmd.Parameters.AddWithValue("@name", txtName.Text.Trim());
cmd.Parameters.AddWithValue("@email", txtEmail.Text.Trim());
cmd.Parameters.AddWithValue("@contact", txtContact.Text.Trim());
cmd.Parameters.AddWithValue("@uquery", txtQuery.Text.Trim());
DataTable DT = new DataTable();
Da.Fill(DT);
ClearAll();
ShowMessage("Query Submitted successfully");
}
catch
{
ShowMessage("Query submit failed!!!");
}
}


This is another code of my contactus page.Here no session or cookie is required.but if i left this page idel for 3 mins and then try to submit my query by clicking the submit button its showing that custom error page named "sessionexpire.html"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900