Solved

Sessionstate mode =SQLServer

Posted on 2012-03-26
5
605 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

792 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