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

Discussion in 'ASP .Net' started by =?Utf-8?B?QW5kcmVhcyBIb2ZtYW5u?=, Apr 15, 2005.

  1. Background:
    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
    Session-management.

    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
    utilisation.

    Problem:
    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:

    --snip--
    Dim ASPFile
    ....
    ASPFile = Request.ServerVariables( "SCRIPT_NAME" )
    ....
    --/snip--

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

    --snip--
    <form target="<%=ASPFile%>?Action=Submit">
    ....
    --/snip--

    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
    thankful. Small changes are still possible, so it wouldn't be a big problem
    to change

    <%=ASPFile%>

    to something like

    <%=GlobalData.ASPFile%>

    if the only chance is to encapsulate the global variables inside some sort
    of module or class - I'm thinking along the lines of putting something like
    this into the Include-file:

    --snip--
    Public Class GlobalData
    Public ASPFile As String
    ...
    ASPFile = Request.ServerVariables( "SCRIPT_NAME" )
    ...
    End Class
    --/snip--

    ...but then I'd still need to know how to correctly instantiate and include
    and use this class.

    Sorry for this newbish question, but no "ASP to ASP.NET"-migration-howto
    seems to address the use of global variables at all, and I've read through
    quite a lot of them lately.

    Thanks for reading,

    Andreas Hofmann
    =?Utf-8?B?QW5kcmVhcyBIb2ZtYW5u?=, Apr 15, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?QW5kcmVhcyBIb2ZtYW5u?=

    Bruce Barker Guest

    there 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
    vars.

    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 vb.net
    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 (sqlwork.com)


    "Andreas Hofmann" <> wrote in
    message news:...
    > Background:
    > 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
    > Session-management.
    >
    > 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
    > utilisation.
    >
    > Problem:
    > 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:
    >
    > --snip--
    > Dim ASPFile
    > ...
    > ASPFile = Request.ServerVariables( "SCRIPT_NAME" )
    > ...
    > --/snip--
    >
    > ..and then all scripts including the Include-file can just use "ASPFile"
    > to
    > reference back to themself like so for example:
    >
    > --snip--
    > <form target="<%=ASPFile%>?Action=Submit">
    > ...
    > --/snip--
    >
    > 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
    > thankful. Small changes are still possible, so it wouldn't be a big
    > problem
    > to change
    >
    > <%=ASPFile%>
    >
    > to something like
    >
    > <%=GlobalData.ASPFile%>
    >
    > if the only chance is to encapsulate the global variables inside some sort
    > of module or class - I'm thinking along the lines of putting something
    > like
    > this into the Include-file:
    >
    > --snip--
    > Public Class GlobalData
    > Public ASPFile As String
    > ...
    > ASPFile = Request.ServerVariables( "SCRIPT_NAME" )
    > ...
    > End Class
    > --/snip--
    >
    > ..but then I'd still need to know how to correctly instantiate and include
    > and use this class.
    >
    > Sorry for this newbish question, but no "ASP to ASP.NET"-migration-howto
    > seems to address the use of global variables at all, and I've read through
    > quite a lot of them lately.
    >
    > Thanks for reading,
    >
    > Andreas Hofmann
    Bruce Barker, Apr 15, 2005
    #2
    1. Advertising

  3. Re: Newbie question: migrating "global variables" from ASP to ASP.

    Thanks for your response Bruce, seems to make a lot of sense what you
    propose - but I still have some questions or problems, perhaps because I'm
    just missing some vital insight (or perhaps because I just bought the wrong
    book to learn ASP.NET, which I think I did)

    You propose:

    > 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" %>


    As I said, that sounds like a good idea, but I'm not able to get it to
    work. I've put all the old global variables and helper functions into a
    class-block and then I tried to have my .aspx-file inherit from that class -
    but I'm at a loss how to make it work.

    My problem begins with the simple fact that I don't know what to put into
    the Inherits="..." area. You've made it "MyStuff.Globals" but I don't get the
    "MyStuff"-part. "Globals" is the name of the class, that's clear, so I need
    to put

    Publich Class Globals
    ...
    End Class

    in some .aspx or .aspx.vb file - and then I've tried to make my main
    ..aspx-file inherit from that class by adding

    <%@ Page Language="vb" AutoEventWireup="false" Inherits="Globals" %>

    but that only ends with the parser saying:

    Parser Error Message: Could not load type 'Globals'

    I'm sure it's some stupid mistake I'm doing here, but I don't get it yet.
    Could you perhaps show me how I'd have to design the two files in question to
    make it work? The one file would be the rewritten "include"-file with the
    definition of the "Globals"-class, and the other file being the page doing
    the actual work. I'd expect them to be something like this:

    __(include.aspx)__
    Public Class Globals
    Inherits System.Web.UI.Page
    Dim ASPFile As String
    ' ...more "global variables" as needed
    End Class

    __(work.aspx)__
    <%@ Page Language="vb" Inherits="Globals" %>
    ....
    <form action="<% Response.Write( ASPFile ) %>">
    ....


    Am I thinking totally wrong here? How do I make it clear for the
    parser/compiler that I want to use the class "Globals" which is defined in
    the file "include.aspx"? *wonders*

    Still quite confused und feeling new(b)ish

    Andreas Hofmann
    =?Utf-8?B?QW5kcmVhcyBIb2ZtYW5u?=, Apr 18, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wayne
    Replies:
    2
    Views:
    467
    Wayne
    Nov 11, 2003
  2. =?Utf-8?B?TWFya3VzIE1jR2Vl?=

    Migrating ASP.NET projects between VS.NET 2002 and VS.NET 2003

    =?Utf-8?B?TWFya3VzIE1jR2Vl?=, Dec 2, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    334
    =?Utf-8?B?TWFya3VzIE1jR2Vl?=
    Dec 6, 2004
  3. Hrvoje Vrbanc
    Replies:
    2
    Views:
    1,327
    =?Utf-8?B?UmFodWwgU29uaQ==?=
    Nov 30, 2005
  4. Alan Campbell
    Replies:
    5
    Views:
    731
    Dorothy Rifai
    Jul 15, 2003
  5. jubelbrus
    Replies:
    5
    Views:
    612
    JohnQ
    Jul 20, 2007
Loading...

Share This Page