G
Guest
I'm trying to write/compile a class that (1) accesses all the intrinsic ASP.NET objects (2) Uses Server.Transfer to redirect a user back to a log in page if a session has expired. I've gotten inconsistent results. The redirection works perfectly if the user session has expired, but throws an exception if it hasn't. Both "ASPIntrinsicObjects" and "Miscfunctions" compile correctly without a hitch, but bomb out upon executio
I start with a Base class that grabs all the intrinsic objects called "ASPIntrinsicObjects". Code follows
Imports Syste
Imports System.We
Imports System.Web.SessionStat
Imports System.Web.UI.Pag
Public Class ASPIntrinsicObject
Private Shared objHttpContext As HttpContex
Private Shared objResponse As HttpRespons
Private Shared objRequest As HttpReques
Private Shared objApplication As HttpApplicationStat
Private Shared objSession As HttpSessionStat
Private Shared objServer as HttpServerUtilit
Shared Sub New(
'Get all intrinsic object
objHttpContext = HttpContext.Current(
objApplication = objHttpContext.Applicatio
objSession = objHttpContext.Current.Session(
objResponse = objHttpContext.Respons
objRequest = objHttpContext.Reques
objServer = objHttpContext.Serve
End Su
Public ReadOnly Shared Property Request() as HttpReques
Ge
Return objReques
End Ge
End Propert
Public ReadOnly Shared Property Response() as HttpRespons
Ge
Return objRespons
End Ge
End Propert
Public ReadOnly Shared Property Session() as HttpSessionStat
Ge
Return objSessio
End Ge
End Propert
Public ReadOnly Shared Property Application() as HttpApplicationStat
Ge
Return objApplicatio
End Ge
End Propert
Public ReadOnly Shared Property Server() as HttpServerUtilit
Ge
Return objServe
End Ge
End Propert
End Clas
---------------------------------------------------------------------
Then, I inherit it through another class called "SessionMonitor". This utilizes a shared method called "CheckForExpiredSession" to server.transfer if the session has expired. This is the method I call on in my asp.net page. Code Follows
Imports Syste
Imports System.We
Imports System.Exceptio
Imports ASPIntrinsicObject
NameSpace MiscFunction
Public Class SessionMonito
Public Shared Sub CheckForExpiredSession(
Tr
if Session("intCustID") is nothing the
Server.Transfer("default.aspx"
end i
catch exc as Exceptio
Throw new ApplicationException(exc.toString()
End Tr
End Su
End Clas
End NameSpac
-------------------------------
The code in my web form is
<%@ Page Language="VB" autoeventwireup="true" Debug="true" Trace="false" %><%@ import Namespace="MiscFunctions" %><%@ import Namespace="System.Data" %><%@ import Namespace="System.Data.SqlClient" %><script runat="server"
Sub Page_Load(Sender as Object, E as EventArgs
SessionMonitor.CheckForExpiredSession(
[more code]
End Su
</SCRIPT
'------------------------------------------------
The exception message is as follows
System.Web.HttpException: Error executing child request for default.aspx. ---> System.NullReferenceException: Object reference not set to an instance of an object. at System.Web.HttpServerUtility.ExecuteInternal(String path, TextWriter writer, Boolean preserveForm) --- End of inner exception stack trace --- at System.Web.HttpServerUtility.ExecuteInternal(String path, TextWriter writer, Boolean preserveForm) at System.Web.HttpServerUtility.Transfer(String path, Boolean preserveForm) at System.Web.HttpServerUtility.Transfer(String path) at MiscFunctions.SessionMonitor.CheckForExpiredSession()
I start with a Base class that grabs all the intrinsic objects called "ASPIntrinsicObjects". Code follows
Imports Syste
Imports System.We
Imports System.Web.SessionStat
Imports System.Web.UI.Pag
Public Class ASPIntrinsicObject
Private Shared objHttpContext As HttpContex
Private Shared objResponse As HttpRespons
Private Shared objRequest As HttpReques
Private Shared objApplication As HttpApplicationStat
Private Shared objSession As HttpSessionStat
Private Shared objServer as HttpServerUtilit
Shared Sub New(
'Get all intrinsic object
objHttpContext = HttpContext.Current(
objApplication = objHttpContext.Applicatio
objSession = objHttpContext.Current.Session(
objResponse = objHttpContext.Respons
objRequest = objHttpContext.Reques
objServer = objHttpContext.Serve
End Su
Public ReadOnly Shared Property Request() as HttpReques
Ge
Return objReques
End Ge
End Propert
Public ReadOnly Shared Property Response() as HttpRespons
Ge
Return objRespons
End Ge
End Propert
Public ReadOnly Shared Property Session() as HttpSessionStat
Ge
Return objSessio
End Ge
End Propert
Public ReadOnly Shared Property Application() as HttpApplicationStat
Ge
Return objApplicatio
End Ge
End Propert
Public ReadOnly Shared Property Server() as HttpServerUtilit
Ge
Return objServe
End Ge
End Propert
End Clas
---------------------------------------------------------------------
Then, I inherit it through another class called "SessionMonitor". This utilizes a shared method called "CheckForExpiredSession" to server.transfer if the session has expired. This is the method I call on in my asp.net page. Code Follows
Imports Syste
Imports System.We
Imports System.Exceptio
Imports ASPIntrinsicObject
NameSpace MiscFunction
Public Class SessionMonito
Public Shared Sub CheckForExpiredSession(
Tr
if Session("intCustID") is nothing the
Server.Transfer("default.aspx"
end i
catch exc as Exceptio
Throw new ApplicationException(exc.toString()
End Tr
End Su
End Clas
End NameSpac
-------------------------------
The code in my web form is
<%@ Page Language="VB" autoeventwireup="true" Debug="true" Trace="false" %><%@ import Namespace="MiscFunctions" %><%@ import Namespace="System.Data" %><%@ import Namespace="System.Data.SqlClient" %><script runat="server"
Sub Page_Load(Sender as Object, E as EventArgs
SessionMonitor.CheckForExpiredSession(
[more code]
End Su
</SCRIPT
'------------------------------------------------
The exception message is as follows
System.Web.HttpException: Error executing child request for default.aspx. ---> System.NullReferenceException: Object reference not set to an instance of an object. at System.Web.HttpServerUtility.ExecuteInternal(String path, TextWriter writer, Boolean preserveForm) --- End of inner exception stack trace --- at System.Web.HttpServerUtility.ExecuteInternal(String path, TextWriter writer, Boolean preserveForm) at System.Web.HttpServerUtility.Transfer(String path, Boolean preserveForm) at System.Web.HttpServerUtility.Transfer(String path) at MiscFunctions.SessionMonitor.CheckForExpiredSession()