>< %@ Application Language="VB" % > > ><object id="LXFramework" runat="server" class="Framework.Framework.App" scope="Application" /> > ><script runat=server> > > Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) > LXFramework.nApplicationMode = 3 > LXFramework.oServer = Server > LXFramework.Initialize() > End Sub > > Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) > LXFramework.ErrorSetup() > End Sub > > Sub Application_PreRequestHandlerExecute(ByVal sender As Object, ByVal e As EventArgs) > Dim loContext As Object = Context.Handler > Dim loType As Object = loContext.GetType() > Dim lcType As String = loType.ToString > > ' .vb and .config not accepted > If lcType = "System.Web.HttpForbiddenHandler" Then > Response.Redirect("Default.aspx") > End If > > End Sub > ></script> >>
>< %@ Page Language="VB" AutoEventWireup="false" Inherits="Framework.Framework.WebForm" % > >>
>Namespace Framework > > Public Class WebForm > Inherits System.Web.UI.Page > > Public oApp As Framework.App = New Framework.App() > > Sub New() > End Sub > > Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init > oApp.nApplicationMode = 3 > oApp.oServer = Server > oApp.Initialize() > oApp.oRequest = Request > oApp.oResponse = Response > oApp.oPage = Me > oApp.BeginRequest() > End Sub > > Sub Page_UnLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Unload > oApp.EndRequest() > oApp.oResponse.Write(oApp.GetJavascriptMessage) > End Sub > > End Class > >End Namespace >>
><script runat="server"> > Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load > Dim loDataEntry As DataEntryPurchase = New DataEntryPurchase(oApp) > loDataEntry.GenerateForm() > End Sub ></script> >>
>Namespace Framework > > Public Class WebForm > Inherits System.Web.UI.Page > > Public oApp As Framework.App = New Framework.App() > > Sub New() > End Sub > > Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init > > ' This is the line which need to be updated so I could get a reference to the global.asax framework object > oApp=LXFramework > > oApp.oRequest = Request > oApp.oResponse = Response > oApp.oServer = Server > oApp.oPage = Me > oApp.BeginRequest() > End Sub > > Sub Page_UnLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Unload > oApp.EndRequest() > oApp.oResponse.Write(oApp.GetJavascriptMessage) > End Sub > > End Class > >End Namespace >>
Framework.App oApp = (Framework.App )Application.StaticObjects.GetObject("LXFramework"");but I fail to see how the code in Page_Init above differs in any real sense to the original code that you had in BeginRequest. You're back to passing a reference into a global object that cannot be quaranteed to be correct when accessed later. You have exactly the same predicament as in the original. Consider just these four lines of code
> oApp.oRequest = Request > oApp.oResponse = Response > oApp.oServer = Server > oApp.oPage = Me > oApp.BeginRequest()By the time BeginRequest() is entered oApp.oRequest could already be invalid!
public class RequestScopeObject { public string cCookie = ""; public string cDecrypt = ""; public string cEncrypt = ""; // etc }Then in BeginRequest():
RequestScopeObject rso = new RequestScopeObject(); //Initialise rso as ness. then: HttpContext.Current.Items.Add("RSO", rso);And in the Framework:
RequestScopeObject rso = (RequestScopeObject)HttpContext.Current.Items["RSO"]; //etcRegards,