Handling Response.Redirect in Session end event in global.asax

Last post 10-16-2009 11:49 AM by fkerrigan. 11 replies.

Sort Posts:

  • Handling Response.Redirect in Session end event in global.asax

    07-24-2007, 8:20 AM
    • Member
      223 point Member
    • anilperugu
    • Member since 12-21-2006, 12:50 PM
    • Hyderabad
    • Posts 64

    Handling Response.Redirect in Session end event in global.asax

  • Re: Handling Response.Redirect in Session end event in global.asax

    07-25-2007, 9:46 PM

    HI, anilperugu:

    Session_End is fired internally by the server, based on an internal timer. Thus, there is no HttpRequest associted when that happens. That is why Response.Redirect or Server.Transferdoes not make sense and will not work.

    If i misunderstand you about your question, please feel free to correct me and i will try to help you with more information.

    I hope the above information will be helpful. If you have any issues or concerns, please let me know. It's my pleasure to be of assistance

    Best Regards,
    __________________________________________________
    Sincerely,
    Rex Lin
    Microsoft Online Community Support

    If there is any question or the issue is not resolved, please feel free to mark the thread as not resolved
  • Re: Handling Response.Redirect in Session end event in global.asax

    07-26-2007, 12:19 AM
    • Member
      223 point Member
    • anilperugu
    • Member since 12-21-2006, 12:50 PM
    • Hyderabad
    • Posts 64

    I need to redirect to some location on session end how can i acheive this at one shot instead of placing code in each page load

  • Re: Handling Response.Redirect in Session end event in global.asax

    07-26-2007, 1:27 AM

     

    I guess that Sesssion end is fired when the session timeout expires.

    So possibly it means that closing a browser means that a seesion has ended.

    If u want to redirect to any page when the session is ended then

    put the following code in the global.asax and please understand

    that the event will be fired only when timeout happens.

     

    Jai Ganesh. J , GSD ,India

    Please Mark As Answer If my reply helped you.

    http://www.onlinepersonaldairy.com. A site to have personal details online. Enjoy.
  • Re: Handling Response.Redirect in Session end event in global.asax

    07-26-2007, 9:28 PM
    Answer

    HI, anilperugu:

    The easiest way what I feel is to use Meta information and get the trick working. Consider we have a page WebPage.aspx add the below code in the the WebPage.aspx.cs file.

     

    private void Page_Load(object sender, System.EventArgs e){      Response.AddHeader("Refresh",Convert.ToString((Session.Timeout * 60) + 5));      if(Session[“IsUserValid”].ToString()==””)             Server.Transfer(“Relogin.aspx”);}

     

     

    In the above code, The WebPage.aspx is refreshed after 5 seconds once the Session is expired. And in the page load the session is validated, as the session is no more valid. The page is redirected to the Re-Login page. Every post-back to the server will refresh the session and the same will be updated in the Meta information of the WebPage.aspx.

    Best Regards,
    __________________________________________________
    Sincerely,
    Rex Lin
    Microsoft Online Community Support

    If there is any question or the issue is not resolved, please feel free to mark the thread as not resolved
  • Re: Handling Response.Redirect in Session end event in global.asax

    07-29-2007, 9:24 PM

    HI, anilperugu:

    We are marking this issue as "Answered". If you have any new findings or concerns, please feel free to unmark the issue.
    Thank you for your understanding!

     

    Best Regards,
    __________________________________________________
    Sincerely,
    Rex Lin
    Microsoft Online Community Support

    If there is any question or the issue is not resolved, please feel free to mark the thread as not resolved
  • Re: Handling Response.Redirect in Session end event in global.asax

    07-31-2007, 2:35 AM
    • Member
      223 point Member
    • anilperugu
    • Member since 12-21-2006, 12:50 PM
    • Hyderabad
    • Posts 64

    do i need to place this code in page load of each page.

  • Re: Handling Response.Redirect in Session end event in global.asax

    07-31-2007, 9:07 PM

    You can create a base page and put the above codes into the page_load event.

    Best Regards,
    __________________________________________________
    Sincerely,
    Rex Lin
    Microsoft Online Community Support

    If there is any question or the issue is not resolved, please feel free to mark the thread as not resolved
  • Re: Handling Response.Redirect in Session end event in global.asax

    08-01-2007, 3:26 AM
    • Contributor
      2,598 point Contributor
    • Sathesh_Pandian
    • Member since 07-23-2007, 3:55 PM
    • Chennai
    • Posts 441

    you can check the session in everypage and if the session is dead you can redirect it to

    another page. the global.asax file is class class file and it will handle the events of the

    sessions and application objects only. we can set some functionalities work along with them.

    In the session end event, you can set some application object like

    application("active")="true"

    then check the application("active") in every page where you can set the redirect method .

     

    Got what you needed. Please mark as answer.
  • Re: Handling Response.Redirect in Session end event in global.asax

    10-29-2008, 7:30 PM
    • Member
      683 point Member
    • rmdw
    • Member since 03-14-2005, 11:03 PM
    • Vancouver, BC, Canada
    • Posts 896

    With my web apps, I always just use the default session timeout of 5 minutes.

    I thought your meta refresh approach was a perfect one until I realized that if the user is on a page that involves a lot of editing, which might normally take a couple of hours, then suddenly after 5 minutes they'll be redirected off of the page to the Login page.  Not acceptable.

    In WinForms programming there's a web to monitor keystrokes and mouseclicks which could be used to perpetual move forward the timeout.  Is there not an equivalent way to do that with ASP.Net programming?

    Robert

    Robert Werner
    Vancouver, BC
    Technical Blog
    Pocket Pollster
  • Re: Handling Response.Redirect in Session end event in global.asax

    10-29-2008, 7:40 PM
    • Member
      664 point Member
    • bipro
    • Member since 01-21-2007, 10:28 PM
    • Sydney, Australia
    • Posts 143

    you'd have to use some javascript to update a timer for the client and/or make an ajax call to the server in the background to keep the session open.

    -JESTER blog|profile

    Don't forget to "Mark as Answer" if a post helps you.

  • Re: Handling Response.Redirect in Session end event in global.asax

    10-16-2009, 11:49 AM
    • Member
      2 point Member
    • fkerrigan
    • Member since 10-16-2009, 11:38 AM
    • Posts 1

    It might be better to use Session.IsNewSession

     

    C#

       private void Page_Load(object sender, System.EventArgs e)
        {    
           Response.AddHeader("Refresh",Convert.ToString((Session.Timeout * 60) + 5));     

          if(Session.IsNewSession) 
              Server.Transfer(“Relogin.aspx”);
        }

     

    VB

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
    
     Response.AddHeader("Refresh", Convert.ToString((Session.Timeout) * 60 + 5))
            If Session.IsNewSession Then
                Server.Transfer("sessionended.aspx")
            End If
    
     End Sub


     

     

     


     

     

     

     

     

     

Page 1 of 1 (12 items)