Link to home
Start Free TrialLog in
Avatar of niceguy971
niceguy971

asked on

Sessionstate mode =SQLServer

I have in web-config:     <sessionState  mode="sql server"  ..>

I tried the code below but line { string cookieHeader = Request.Headers["Cookie"]; }

gives me an Error. Is it related to the fact that sessionState  mode is Sql server??

If so how can I modify the below code to check if session is expired when sessionState  mode="sql server" ??

I found the below info at http://forums.asp.net/t/1138444.aspx. It shows how to check if session is expired

protected void Page_Load()
{
   if (Context.Session != null)

   {
      if (Session.IsNewSession)
      {
         string cookieHeader = Request.Headers["Cookie"];

         if ((null != cookieHeader) && (cookieHeader.IndexOf("ASP.NET_SessionId") >= 0))

         {
            Response.Redirect("sessionTimeout.htm");
         }
      }
   }
}

Thanks
SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of niceguy971
niceguy971

ASKER

Yes I tried this code. I did debug it also.  It does Not give an error (sorry for the unclear statement in my original question).

The expression { null != cookieHeader } returns true;

but cookieHeader.IndexOf("ASP.NET_SessionId") returns -1 ..so

(null != cookieHeader) && (cookieHeader.IndexOf("ASP.NET_SessionId") >= 0) returns false

and line Response.Redirect("sessionTimeout.htm") never executed.

How can I modify the code to check if session is expired when sessionState  mode="sql server" ??

Thanks
I think you can remove the

if ((null != cookieHeader) && (cookieHeader.IndexOf("ASP.NET_SessionId") >= 0))

condition and see if it redirects correctly.
Thanks