Problem with isNewSession

Z

zee

Iam having problem with IsNewSession can any1 plz help me to run this
code
which is listed on many websites

this is my code for validating session
-----------------------------------------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (Context.Session != null)
{
if (Context.Session.IsNewSession)
{
string sCookieHeader = Page.Request.Headers["Cookie"];
if ((null != sCookieHeader) &&
(sCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
{
if (Page.Request.IsAuthenticated)
{
FormsAuthentication.SignOut();
}

Server.Transfer("SessionTimeout.aspx");
}
}
}
}
---------------------------------------------------
The problem is "every time its showing IsNewSession=true "

and what confusing is let say i have a login page

protected void LoginButton_Click(object sender, EventArgs e)
{
if (txtUName.Text.Trim() ==
ConfigurationManager.AppSettings["UserName"].Trim() &&
txtPassword.Text.Trim() ==
ConfigurationManager.AppSettings["Password"].Trim())
{
FormsAuthentication.SetAuthCookie(txtUName.Text, false);

// Session["Problem"] ="hello";
Response.Redirect("adminindex.aspx");
}
else
litFailureText.Text = "Your login attempt was not
successful, please try again";
}

In the above code u can see "//Session["Problem"] ="hello" " which is
commented so then it redirect to "adminindex.aspx" its shows
IsNewSession=true

If i undo the comment like this "Session["Problem"] ="hello"" then on
"adminindex.aspx" it will show
IsNewSession=false;

Why its necessay to set any session variable at login to run this code

help
 
B

bruce barker

you are confusing session and authentication. authentication has its own
cookie and does not use session. session and authentication have
independent life cycles.

-- bruce (sqlwork.com)
 

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

Top