1

I am trying to refactor a classic asp code base. For the most part it is going well. It had lots of code duplication for different language versions of the site, so for 6 languages the site was replicated 5 times.

I have used json language files and have managed to make it all far more dynamic and it works lovely.

What I am trying to do now is make the Language class a global object throughout the application for ease of use.

I have used global.asa but the instructions and tutorials I find are very minimal and don't really carry anything I am understanding properly.

I have 2 files:

global.asa

<!--#include virtual="/Five/Classes/Language.asp"-->

<object runat="server" scope="session" id="Lang" progid="Language">
    Lang = New Language
</object>

and test.asp

<%
Lang.LoadLanguageFile("reportAbuse")
%>

<%= Lang.iString("strTitle") %>

what happens though is I receive

Microsoft VBScript runtime error '800a01a8'

Object required: 'Lang'

/Five/0/test.asp, line 2

I cannot, having looked all around here and the web find anything more than:

GLOBAL.ASA:

<object runat="server" scope="session" id="MyAd" progid="MSWC.AdRotator">
</object>

You could reference the object "MyAd" from any page in the ASP application:

SOME .ASP FILE:

<%=MyAd.GetAdvertisement("/banners/adrot.txt")%>
  • You might find [this answer](https://stackoverflow.com/a/37458940/692942) useful. – user692942 Dec 14 '19 at 18:31
  • @Lankymart many thanks, that answer is useful and may use some of the ideas within. However, my question is more specific to the use of global objects within the scopes of session and application. ASP has this solution via the declaration of the objects within the global.asa file but I fail to understand its use. I have several other classes that I also wish to use globally. – Ron Appleton Dec 14 '19 at 19:04
  • It doesn't work and wouldn't recommend trying it. Worked with Classic ASP for years and trying to store complex objects in the session never works, way better to store the data in a serialised format and use an `#include` to define functions for getting and setting the data. – user692942 Dec 14 '19 at 19:49
  • @Lankymart ok, so maybe I need to explain better. So for the localisation stuff, as I say thats all done and working lovely and the language strings are needed on every page, so I thought loading an object at Application level would be a good fit for that and just call Lang.iString("whatever") rather than including on every page, may as well share the memory, I also communicate with 2 servers, 1.DirServer, 2. CacheServer on a user level so thought session level would be good for that, the servers share a response protocol so thought application level a good fit. – Ron Appleton Dec 15 '19 at 00:13
  • Its basically to avoid hundreds of include statements and object declarations and initilisations across the codebase. – Ron Appleton Dec 15 '19 at 00:16
  • Last year we did a similar reconfiguration of our stores when we went multilingual. The way we set it up was to create a function that fetched the current sessions language (which is set at the top depending on which domain the user is on) and for each field where we wanted standard text we created a database entry with the information. So for example we call getText(language, "top_menu_title") and it fetches that from the database. The biggest benefit of this method is that I can call it from both front and backend servers and use it regulary for standardized mails and whatever else needs it. – Daniel Nordh Dec 17 '19 at 08:17

1 Answers1

0

You cannot use VBScript classes as persisted objects in Classic ASP. The example you give is a COM object scoped to the session which is different from using a POCO class in VBScript.

If you want to implement a scoped COM object you would need to build a DLL and implement your class there then expose it to COM registering it where it can then be accessed via Classic ASP. However, you will probably have issues with the data being persisted (see link).

There may be some special-ist requirements for a COM library scoped to a session but I'm not aware of any.


Useful links

user692942
  • 16,398
  • 7
  • 76
  • 175