So I've got a list of functions written in ASP Classic which I include into every page within my application(s). This file is getting quite big and in most scenarios needs to be called 4-5 times for each page load because of the way I structure my pages (sitehead.asp,sitefoot.asp,sidemain.asp, etc). Thus, i'm trying to compile them as a COM/DLL object and simply create an instance of the object in the global.asa and reference the object's methods and properties on any page.
I've done this. It's working great actually and I've just reduced the server load astronomically in the process which i'm quite pleased with. The problem is, some of the functions use ASP objects like the Session object or the Request object, etc. Those particular functions do not work, well, they do but not in the way I want them to.
I've researched this and added in a reference to the ASP Object Library as well as the COM+ Services Type Library.
So here's the problem:
I create an instance of the object in the global.asa - I make calls to the functions within the class object on any other ASP page and most of them work fine, except for the ones that use ASP objects.
However, when I create an instance of the object in my ASP page directly and make a direct call to the function which uses the ASP code - it works. In other words, if i do it directly on the page rather than creating a global object in the global.asa it's golden.
That's wonderful. However, this means I will have to create an instance of the object in every single one of my ASP pages which defeats the purpose entirely.
I'm sure it has something to do with the way I'm initiating the Response objects, etc
Below is the code, and a small function which uses the asp response object to write out hello world.
Expand|Select|Wrap|Line Numbers
- Public Sub OnStartPage(SC As ASPTypeLibrary.ScriptingContext)
- Set Response = SC.Response
- Set Session = SC.Session
- Set Application = SC.Application
- Set Request = SC.Request
- Set Server = SC.Server
- End Sub
- Sub Echo()
- Response.Write "hello world"
- End Sub
- Public Sub OnEndPage()
- Set Response = Nothing
- Set Session = Nothing
- Set Application = Nothing
- Set Request = Nothing
- Set Server = Nothing
- End Sub
Expand|Select|Wrap|Line Numbers
- 'The global.asa object creation...
- <OBJECT id="oApp" progid="oApplication.oApp" runat="server" scope="application"></OBJECT>
- 'the test page to call functions from the object
- <%
- Set oApplication = Server.CreateObject("oApplication.oApp")
- oApplication.Echo()
- Set oApplication = Nothing
- oApp.Echo()
- %>
Thanks
Sincerely,
Mark