Newbie question: migrating "global variables" from ASP to ASP.NET

Newbie question: migrating "global variables" from ASP to ASP.NET

Post by QW5kcmVhcy » Sat, 16 Apr 2005 20:38:02

We've been using ASP to power our companys intranet ever since around 1998,
and over time we've developed quite a lot of separate web-applications for
different problems. Lately our IT has migrated to Windows 2003 Server and IIS
6.0, and all we've done so far is copy our old ASP files and scripts over and
keep using them.

Unfortunately there have been some problems which we're not able to solve -
it seems as if the old ASP session-handling (using the Session()-object)
stalls the webserver from time to time - static HTML-files are still
delivered, plain ASP-scripts are working, too, but everything using Sessions
is unavailable until the IIS-service is restarted - don't ask me why, as I
said, we were not able to pinpoint the error, it just seems related to

Our workaround right now is to recycle the IIS-process every 30 minutes -
that way the server only stalls every few days. Unfortunately by using this
workaround we lose all Sessions every 30 minutes which is no situation I like.

As ASP.NET offers a "new" Session-handling which doesn't stall the server
we'd like to use it, i.e. we'd like to migrate our existing ASP scripts to
ASP.NET. We don't have the knowledge nor the time nor the manpower to rewrite
all applications from scratch so what we'd like to do is only change the
things that really need to be changed in order for our old scripts to run as
.aspx - even if that means sacrificing performance, the server still has
plenty to spare - if the server runs stable I don't mind a higher CPU

As I said, we've started scripting in ASP back in 1998, and in fact there's
still a lot of "old code" and "old concepts" in our scripts, things we just
copied again and again. And one of these "old concepts" is now making it hard
for me to switch existing applications to ASP.NET.

In 1998 we've put together a separate include-file containing all commonly
used functions and variables, and almost every script includes and uses this
file nowadays. My problem is that we've defined quite a lot of global
variables in the include-file, and these variables are also used and required
by almost every script. The Include-file contains things like this:

Dim ASPFile
ASPFile = Request.ServerVariables( "SCRIPT_NAME" )

..and then all scripts including the Include-file can just use "ASPFile" to
reference back to themself like so for example:

<form target="<%=ASPFile%>?Action=Submit">

Now I know that global variables are probably the second most stupid idea
after the invention of "goto", and I'd really like to rewrite our whole
codebase to get rid of them - but we just don't have the time, so I'm trying
to make these "global variables" work in ASP.NET in some way or another with
the goal to keep the necessary changes to our scripts as small as possible.

Unfortunately I'm quite new to this whole .NET-thing, and while I can see
the good ideas it brings along I'm not able to put them to good use yet, i.e.
I don't know how to use "classes" or "modules" or "inheritance" to end up
with the needed information being available globally.

So if anyone could offer me some advice how to change our Include-file to
make our old global variables "compatible" with ASP.NET without having to
migrate each and every of our existing scripts to strict ASP.NET I'd be

Newbie question: migrating "global variables" from ASP to ASP.NET

Post by Bruce Bark » Sun, 17 Apr 2005 01:53:55

here is nothing wrong with the global var approach you are using, just
don't make them shared (don't use a vb module). they just turn into members

create a class file, and define all you global vars and mrethods in it. then
have each page inherit from that class, rather then using a file include.

<%@ Page language="vb" Inherits="MyStuff.Globals" %>

if you'd used jscript, your code would have been compatible, but the
does not match vbscript. you will need to change you code quite a bit. also
there are different rule for code blocks:

1) inline script or variable defs must be inside <% %> blocks
2) functions and subs must be defined in script blocks <script runat=server>
3) script blocks can only contain function and sub definations.

-- bruce (

"Andreas Hofmann" < XXXX@XXXXX.COM > wrote in
message news: XXXX@XXXXX.COM ...