trouble utilizing intrinsic objects in custom class

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()
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top