By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,663 Members | 762 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,663 IT Pros & Developers. It's quick & easy.

COM/DLL object with ASP Reference

Expert 100+
P: 346

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
  1.     Public Sub OnStartPage(SC As ASPTypeLibrary.ScriptingContext)
  2.       Set Response = SC.Response
  3.       Set Session = SC.Session
  4.       Set Application = SC.Application
  5.       Set Request = SC.Request
  6.       Set Server = SC.Server
  7.     End Sub
  9.     Sub Echo()
  10.         Response.Write "hello world"
  11.     End Sub
  13.     Public Sub OnEndPage()
  14.       Set Response = Nothing
  15.       Set Session = Nothing
  16.       Set Application = Nothing
  17.       Set Request = Nothing
  18.       Set Server = Nothing
  19.     End Sub
This first call, oApplication.Echo() works fine, does what it's supposed to do.. but the second call, oApp.Echo(), throws an error. It's not because the object (oApp) isn't set properly, because it is.. all the other functions work.

Expand|Select|Wrap|Line Numbers
  2. 'The global.asa object creation...
  3. <OBJECT id="oApp" progid="oApplication.oApp" runat="server" scope="application"></OBJECT>
  5. 'the test page to call functions from the object
  6. <%
  7. Set oApplication = Server.CreateObject("oApplication.oApp")
  8. oApplication.Echo()
  9. Set oApplication = Nothing
  10. oApp.Echo()
  11. %>
Hope someone can give me a hand here.


Jan 22 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.