ASP.NET - Context.session siempre es nothing

 
Vista:

Context.session siempre es nothing

Publicado por Marco (3 intervenciones) el 01/09/2010 21:26:29
Problema con Context.Session

Hola a todos.

He puesto un HttpModule para manejar el inicio y cierre de sesion, en vez del Global.asax.

El problema está en todos los eventos que usan Context.Session, ya que siempre devuelve Nothing. En donde y como se debe inicializar este objeto o qué está faltando?

Gracias de antemano.

El código va a continuación:

-----------inicia modulo ---------------

Imports System
Imports System.Web
Imports System.Collections

Namespace gdc

Public Class MyHTTPHandler
Implements IHttpModule
Implements IRequiresSessionState

Public ReadOnly Property ModuleName() As [String]
Get
Return "MyHTTPHandler"
End Get
End Property

Public Sub Init(ByVal application As HttpApplication) Implements IHttpModule.Init
AddHandler application.BeginRequest, AddressOf Me.Application_BeginRequest
AddHandler application.EndRequest, AddressOf Me.Application_EndRequest

' agregar handlers para Session_Start y Session_end
Dim modules As HttpModuleCollection = application.Modules
Dim [module] As IHttpModule = modules("Session")
Dim stateModule As SessionStateModule = DirectCast([module], SessionStateModule)
AddHandler stateModule.Start, AddressOf Me.Session_Start
AddHandler stateModule.End, AddressOf Me.Session_End

End Sub

Private Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim application As HttpApplication = CType(sender, HttpApplication)
Dim context As HttpContext = application.Context

If Not IsNothing(context.Session) Then ' <-- Esto siempre devuelve Nothing

'... codigo especifico para registrar la pagina en la variable de sesion

End If

End Sub

Private Sub Application_EndRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim application As HttpApplication = CType(sender, HttpApplication)
Dim context As HttpContext = application.Context

End Sub

Private Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Se desencadena cuando se inicia la sesión
Dim application As HttpApplication = CType(sender, HttpApplication)
Dim context As HttpContext = application.Context

Try
If Not IsNothing(context.Session) Then ' <-- Esto siempre devuelve Nothing
'... codigo especifico para inicializar las variables de sesión
End If
Catch ex As Exception

End Try
End Sub

Private Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Se desencadena cuando termina la sesión

'....código especifico para guardar los detalles de la sesion en la base de datos

End Sub

Public Sub Dispose() Implements IHttpModule.Dispose

End Sub
End Class
----------- termina modulo ---------------

En web.config ha registrado el HttpModule y lo invoca sin problemas:
...
<httpModules>
<add name="MyHTTPHandler" type="gdc.MyHTTPHandler" />
</httpModules>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de roger

RE:Context.session siempre es nothing

Publicado por roger (311 intervenciones) el 01/09/2010 23:33:16
segun este post http://forums.asp.net/p/959808/1204052.aspx y este http://www.mail-archive.com/[email protected]/msg02271.html, puedes usar las variables de sesion en el evento PreRequestHandlerExecute.

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Context.session siempre es nothing

Publicado por Marco (3 intervenciones) el 02/09/2010 13:20:18
Hey, funcionó! Gracias por la nota Roger. Salvaste el día.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar