Click here to Skip to main content
15,883,730 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In my website, I inherit each web page's class from a base class for checking session timeout

VB
Partial Class Default
    Inherits SessionManagement
.
.
End Class


SessionManagement class looks as

Imports Microsoft.VisualBasic


Public Class SessionManagement
    Inherits System.Web.UI.Page

    Public m_bIgnoreSessionTimeout As Boolean = False
  

    Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
        Dim sPageName As String = String.Empty

        Try
            MyBase.OnInit(e)

            If m_bIgnoreSessionTimeout = True Then
                Exit Sub
            End If



            If Not Context.Session Is Nothing Then

                If Session.IsNewSession = True Then

                    Dim sCookieHeader As String = Request.Headers("Cookie")

                    If IsNothing(sCookieHeader) = False Then

                        If sCookieHeader.IndexOf("ASP.NET_SessionId") > -1 Then


                        
                            Session.Abandon()


                            
                            Response.Redirect("~/SessionTimeout.htm", False)
                            HttpContext.Current.ApplicationInstance.CompleteRequest()



                            'End If



                      

                    End If

                End If

            End If
        Catch ex As Exception
            Session.Abandon()

         
            Response.Redirect("~/SessionTimeout.htm", False)
            HttpContext.Current.ApplicationInstance.CompleteRequest()

        End Try
    End Sub


End Class



The sessiontimeout.htm page exists in the same folder as of default.aspx.

When the session expires or times out, the default page tries to go to sessiontimeout.htm but gives error 400

I right clicked on it and checked the url, it showed me

http://<webserver name="">/MyWebSite/%2fMyWebSite%2fsessiontimeout.htm

My question is why it did not try to redirect to the path as http://<webserver name="">/MyWebSite/sessiontimeout.htm and instead chose the path above by appending <sitename>/sessiontimeout.htm to the base url?

Thanks

Vijay
Posted
Comments
WALEED SHAKER 11-Oct-10 11:22am    
hi dear

please try

Response.Redirect("SessionTimeout.htm", False)
vjvjvjvj 11-Oct-10 11:28am    
Hi Waleed, I had tried that also. Did not work for me.
Brij 11-Oct-10 12:24pm    
Your problem resolved? Comment the line HttpContext.Current.ApplicationInstance.CompleteRequest(), then try
vjvjvjvj 12-Oct-10 11:22am    
No I could not resolve the problem. It still tries to go to http://localhost:3227/ClientSite/%2fClientSite%2fSessionTimeout.htm

1 solution

Try this:

Response.Redirect(ResolveURL("~/sessiontimeout.aspx"))


It should resolve the url for the browser. You could otherwise use Server.Transfer instead of Response.Redirect and save the round trip to the client.

Good luck!
 
Share this answer
 
Comments
vjvjvjvj 11-Oct-10 13:03pm    
Thanks. I am going to try tomorrow and I will let you know.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900