Solved

Sessionstate mode =SQLServer

Posted on 2012-03-26
5
599 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
Comment Utility
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
Comment Utility
>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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

763 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

14 Experts available now in Live!

Get 1:1 Help Now