Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Major mixup in two ASP.NET transactions
Message
 
To
03/09/2006 22:53:52
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01150471
Message ID:
01150780
Views:
45
You don't want to go thorugh all of this. A static property hung off an object somewhere will let you keep a single instance of your oApp object around. You don't want to require a special page class just to recreate this object - you should should treat the oApp object as a singleton which is going to be much more efficient resulting in smaller memory footprint (no objects created over and over for every hit).

Performance is probably not a big concern if hte instantiation is pretty light weight, but if you're doing things like reading settings from an INI (as you mentioned earlier) file you surely don't want to do that on every hit!

Actually looking at this a little closer - a static won't work if you're assigning request specific items to this object. Why are you even storing Request and Response? Those objects are ALWAYS available with:

HttpContext.Current.Response
HttpContext.Current.Request

from anywhere where HttpRequest/httpResponse are visible.

There's no need (in fact it a bad idea because the object reference may keep the garbage collector from cleaning up the references if your code fails to clean up its object) to save those vars.

+++ Rick ---

>>No simple fix for these. Maybe you should store the items that aren't Request/Response related in the Context.Items collection rather than as framework properties. It would mean fairly substantial changes to your existing code but I see no obvious alternative.
>
>I found something simple.
>
>First of all, the global.asax now only contains this:
>
>
>< %@ 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>
>
>
>Secondly, all the ASPX pages inherits from the WebForm class of the framework like this:
>
>
>< %@ Page Language="VB" AutoEventWireup="false" Inherits="Framework.Framework.WebForm" % >
>
>
>Then, the Web Form class is having everything it needs to instantiate the framework and make it available at the page level. Then, from the page level, I can then use a reference to oApp to start things up:
>
>
>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>
>
>
>This works and it responds fast. However, I want it to be faster. The next goal would be to get a reference to the global.asax LXFramework object in the WebForm class so I would be able to have the class like this which the initialization to the framework would be removed because I would be able to get a referenced copy of LXFramework from global.asax.
>
>
>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
>
>
>But, this is the part that is missing. I don't know if it is possible to get a reference to a global.asax object from a class. Is the current context able to help me in this case?
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform