Solved

Sessionstate mode =SQLServer

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now