Solved

Sessionstate mode =SQLServer

Posted on 2012-03-26
5
604 Views
Last Modified: 2012-04-25
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
0
Comment
Question by:niceguy971
  • 2
  • 2
5 Comments
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 250 total points
ID: 37769789
What error do you get ? I don't think you can catch the "session expired"


Session_End doesn't fire in SQL Server session state mode.

For clearing the expired session data: SQL Server Agent needs to be running. It runs a
stored proc every minute which gets rid of expired session data
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 250 total points
ID: 37772242
>I found the below info at http://forums.asp.net/t/1138444.aspx. It shows how to check if session is expired

And did you try it?
0
 

Author Comment

by:niceguy971
ID: 37775051
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
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37776368
I think you can remove the

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

condition and see if it redirects correctly.
0
 

Author Closing Comment

by:niceguy971
ID: 37895635
Thanks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tutorial for ebay api 3 35
REXEX help Part 2 2 25
VB.NET 2008 - Windows Protected Your PC 7 17
Client Validating 2 date fields, required & comparison 1 29
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question