Bromberg's Session Timeout Control

Discussion in 'ASP .Net' started by SAL, Dec 18, 2007.

  1. SAL

    SAL Guest

    Hello,
    I'm trying to implement Peter Bromberg's Session Timeout Control:
    http://www.eggheadcafe.com/articles/20051228.asp
    in ASP.NET 2.0 and am finding that the code never fires. I'm not sure what
    I'm doing wrong here. Yes, it would be easy enough to place some of that
    code in a class, or test for a particular Session variable but it would be
    nice to have a control to drop on a web form and have it just work. Can
    anyone tell me what I might be missing. Sorry, I'm still pretty new to
    ASP.NET:

    Imports System
    Imports System.ComponentModel
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI

    <DefaultProperty("Text"), _
    ToolboxData("<{0}:SessionTimeoutControl
    runat=server></{0}:SessionTimeoutControl>")> _
    Partial Class UserControls_SessionTimeOutControl
    Inherits System.Web.UI.UserControl

    ' reference for this control:
    ' http://www.eggheadcafe.com/articles/20051228.asp

    #Region "Private member variables"
    Private mRedirectUrl As String
    #End Region

    #Region "Public Properties"
    <Bindable(True), Category("Appearance"), DefaultValue("")> _
    Public Property RedirectUrl() As String
    Get
    Return mRedirectUrl
    End Get
    Set(ByVal value As String)
    mRedirectUrl = value
    End Set
    End Property

    Public Overrides Property Visible() As Boolean
    Get
    Return False
    End Get
    Set(ByVal value As Boolean)
    '
    End Set
    End Property

    Public Overrides Property EnableViewState() As Boolean
    Get
    Return False
    End Get
    Set(ByVal value As Boolean)
    'MyBase.EnableViewState = value
    End Set
    End Property
    #End Region

    #Region "Protected Members"
    Protected Overrides Sub Render(ByVal writer As
    System.Web.UI.HtmlTextWriter)
    If HttpContext.Current Is Nothing Then
    writer.Write("[ *** SessionTimeout: " + Me.ID + " *** ]")
    End If
    MyBase.Render(writer)
    End Sub

    Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
    MyBase.OnPreRender(e)
    If Me.mRedirectUrl Is Nothing Then
    Throw New InvalidOperationException("RedirectUrl Property Not
    Set.")
    End If
    If Context.Session IsNot Nothing Then
    Dim sCookieHeader As String = Page.Request.Headers("Cookie")
    If (sCookieHeader IsNot Nothing) And
    (sCookieHeader.IndexOf("ASP.NET_SessionId") >= 0) Then
    If Page.Request.IsAuthenticated Then
    FormsAuthentication.SignOut()
    End If
    Page.Response.Redirect(Me.mRedirectUrl)
    End If
    End If
    End Sub
    #End Region
    End Class


    SAL
     
    SAL, Dec 18, 2007
    #1
    1. Advertising

  2. SAL,
    It worked fine when I wrote the article. Of course, you have translated in
    to VB.NET so you may have a little boo-boo in there somewhere. Also, there
    have been some minor changes in Session behavior since ASP.NET 2.0 came out.
    I'd just set a breakpoint on the pertinent line in debug mode and test it
    from another machine (not from localhost).
    -- Peter
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    MetaFinder: http://www.blogmetafinder.com


    "SAL" wrote:

    > Hello,
    > I'm trying to implement Peter Bromberg's Session Timeout Control:
    > http://www.eggheadcafe.com/articles/20051228.asp
    > in ASP.NET 2.0 and am finding that the code never fires. I'm not sure what
    > I'm doing wrong here. Yes, it would be easy enough to place some of that
    > code in a class, or test for a particular Session variable but it would be
    > nice to have a control to drop on a web form and have it just work. Can
    > anyone tell me what I might be missing. Sorry, I'm still pretty new to
    > ASP.NET:
    >
    > Imports System
    > Imports System.ComponentModel
    > Imports System.Web
    > Imports System.Web.Security
    > Imports System.Web.UI
    >
    > <DefaultProperty("Text"), _
    > ToolboxData("<{0}:SessionTimeoutControl
    > runat=server></{0}:SessionTimeoutControl>")> _
    > Partial Class UserControls_SessionTimeOutControl
    > Inherits System.Web.UI.UserControl
    >
    > ' reference for this control:
    > ' http://www.eggheadcafe.com/articles/20051228.asp
    >
    > #Region "Private member variables"
    > Private mRedirectUrl As String
    > #End Region
    >
    > #Region "Public Properties"
    > <Bindable(True), Category("Appearance"), DefaultValue("")> _
    > Public Property RedirectUrl() As String
    > Get
    > Return mRedirectUrl
    > End Get
    > Set(ByVal value As String)
    > mRedirectUrl = value
    > End Set
    > End Property
    >
    > Public Overrides Property Visible() As Boolean
    > Get
    > Return False
    > End Get
    > Set(ByVal value As Boolean)
    > '
    > End Set
    > End Property
    >
    > Public Overrides Property EnableViewState() As Boolean
    > Get
    > Return False
    > End Get
    > Set(ByVal value As Boolean)
    > 'MyBase.EnableViewState = value
    > End Set
    > End Property
    > #End Region
    >
    > #Region "Protected Members"
    > Protected Overrides Sub Render(ByVal writer As
    > System.Web.UI.HtmlTextWriter)
    > If HttpContext.Current Is Nothing Then
    > writer.Write("[ *** SessionTimeout: " + Me.ID + " *** ]")
    > End If
    > MyBase.Render(writer)
    > End Sub
    >
    > Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
    > MyBase.OnPreRender(e)
    > If Me.mRedirectUrl Is Nothing Then
    > Throw New InvalidOperationException("RedirectUrl Property Not
    > Set.")
    > End If
    > If Context.Session IsNot Nothing Then
    > Dim sCookieHeader As String = Page.Request.Headers("Cookie")
    > If (sCookieHeader IsNot Nothing) And
    > (sCookieHeader.IndexOf("ASP.NET_SessionId") >= 0) Then
    > If Page.Request.IsAuthenticated Then
    > FormsAuthentication.SignOut()
    > End If
    > Page.Response.Redirect(Me.mRedirectUrl)
    > End If
    > End If
    > End Sub
    > #End Region
    > End Class
    >
    >
    > SAL
    >
    >
    >
     
    Peter Bromberg [C# MVP], Dec 18, 2007
    #2
    1. Advertising

  3. SAL

    SAL Guest

    The code works fine if I stick it in the PageError event.
    The real problem is getting the OnPreRender to fire. It doesn't step into
    that code at all and I have
    AutoEventWireup="true"



    SAL

    "Peter Bromberg [C# MVP]" <> wrote in message
    news:...
    > SAL,
    > It worked fine when I wrote the article. Of course, you have translated in
    > to VB.NET so you may have a little boo-boo in there somewhere. Also, there
    > have been some minor changes in Session behavior since ASP.NET 2.0 came
    > out.
    > I'd just set a breakpoint on the pertinent line in debug mode and test it
    > from another machine (not from localhost).
    > -- Peter
    > Site: http://www.eggheadcafe.com
    > UnBlog: http://petesbloggerama.blogspot.com
    > MetaFinder: http://www.blogmetafinder.com
    >
    >
    > "SAL" wrote:
    >
    >> Hello,
    >> I'm trying to implement Peter Bromberg's Session Timeout Control:
    >> http://www.eggheadcafe.com/articles/20051228.asp
    >> in ASP.NET 2.0 and am finding that the code never fires. I'm not sure
    >> what
    >> I'm doing wrong here. Yes, it would be easy enough to place some of that
    >> code in a class, or test for a particular Session variable but it would
    >> be
    >> nice to have a control to drop on a web form and have it just work. Can
    >> anyone tell me what I might be missing. Sorry, I'm still pretty new to
    >> ASP.NET:
    >>
    >> Imports System
    >> Imports System.ComponentModel
    >> Imports System.Web
    >> Imports System.Web.Security
    >> Imports System.Web.UI
    >>
    >> <DefaultProperty("Text"), _
    >> ToolboxData("<{0}:SessionTimeoutControl
    >> runat=server></{0}:SessionTimeoutControl>")> _
    >> Partial Class UserControls_SessionTimeOutControl
    >> Inherits System.Web.UI.UserControl
    >>
    >> ' reference for this control:
    >> ' http://www.eggheadcafe.com/articles/20051228.asp
    >>
    >> #Region "Private member variables"
    >> Private mRedirectUrl As String
    >> #End Region
    >>
    >> #Region "Public Properties"
    >> <Bindable(True), Category("Appearance"), DefaultValue("")> _
    >> Public Property RedirectUrl() As String
    >> Get
    >> Return mRedirectUrl
    >> End Get
    >> Set(ByVal value As String)
    >> mRedirectUrl = value
    >> End Set
    >> End Property
    >>
    >> Public Overrides Property Visible() As Boolean
    >> Get
    >> Return False
    >> End Get
    >> Set(ByVal value As Boolean)
    >> '
    >> End Set
    >> End Property
    >>
    >> Public Overrides Property EnableViewState() As Boolean
    >> Get
    >> Return False
    >> End Get
    >> Set(ByVal value As Boolean)
    >> 'MyBase.EnableViewState = value
    >> End Set
    >> End Property
    >> #End Region
    >>
    >> #Region "Protected Members"
    >> Protected Overrides Sub Render(ByVal writer As
    >> System.Web.UI.HtmlTextWriter)
    >> If HttpContext.Current Is Nothing Then
    >> writer.Write("[ *** SessionTimeout: " + Me.ID + " *** ]")
    >> End If
    >> MyBase.Render(writer)
    >> End Sub
    >>
    >> Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
    >> MyBase.OnPreRender(e)
    >> If Me.mRedirectUrl Is Nothing Then
    >> Throw New InvalidOperationException("RedirectUrl Property Not
    >> Set.")
    >> End If
    >> If Context.Session IsNot Nothing Then
    >> Dim sCookieHeader As String = Page.Request.Headers("Cookie")
    >> If (sCookieHeader IsNot Nothing) And
    >> (sCookieHeader.IndexOf("ASP.NET_SessionId") >= 0) Then
    >> If Page.Request.IsAuthenticated Then
    >> FormsAuthentication.SignOut()
    >> End If
    >> Page.Response.Redirect(Me.mRedirectUrl)
    >> End If
    >> End If
    >> End Sub
    >> #End Region
    >> End Class
    >>
    >>
    >> SAL
    >>
    >>
    >>
     
    SAL, Dec 18, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Davisro
    Replies:
    3
    Views:
    406
    bruce barker
    Apr 29, 2004
  2. Davisro
    Replies:
    1
    Views:
    389
    George Ter-Saakov
    May 3, 2004
  3. saywhat

    Hats off to Peter Bromberg

    saywhat, Jun 4, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    299
    saywhat
    Jun 4, 2006
  4. =?Utf-8?B?Um9iSEs=?=
    Replies:
    4
    Views:
    5,294
    =?Utf-8?B?Um9iSEs=?=
    Apr 11, 2007
  5. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,293
    Brian Candler
    Oct 6, 2004
Loading...

Share This Page