Why does a class created in global.asa Application_Start get removed right away?

Discussion in 'ASP General' started by Grant Schenck, Apr 14, 2005.

  1. Hello,

    I posted an this issue before but I'm clearer on what is going on.

    I have a simple web site with a global.asa and a single .asp file.

    In global.asa I handle both Application_OnStart and Application_OnEnd (see
    below.)

    The ShoreTelMakeCallTransfer object is a simple VB test object which
    currently just logs class_initialize and class_terminate along with
    OnStartPage and OnEndPage.

    When I acess my ASP page, I see the folowing output from my logging:

    --> Class_Initialize
    <-- Class_Initialize

    --> OnStartPage
    <-- OnStartPage

    --> OnEndPage
    <-- OnEndPage

    --> Class_Terminate
    <-- Class_Termiante

    What I don't understand is why Class_Terminate is called?

    Based on the fact that in Application_OnStart I:

    set Application("ShoreTelMakeCallTransfer") = ShoreTelMakeCallTransfer

    Shouldn't that cause the object to stay loaded????

    Thanks, Grant Schenck

    -------------------------------------------------------
    <SCRIPT LANGUAGE=VBScript RUNAT=Server>
    Option Explicit

    Sub Application_OnStart
    On Error Resume Next
    Dim ShoreTelMakeCallTransfer
    Application("ShoreTelMakeCallTransfer") = NULL
    set ShoreTelMakeCallTransfer =
    Server.CreateObject("STMakeCallTransfer.STObject")
    set Application("ShoreTelMakeCallTransfer") = ShoreTelMakeCallTransfer
    End Sub

    Sub Application_OnEnd
    On Error Resume Next
    Dim ShoreTelMakeCallTransfer
    set ShoreTelMakeCallTransfer = Application("ShoreTelMakeCallTransfer")
    set Application("ShoreTelMakeCallTransfer") = NULL
    Application.Contents.Remove("ShoreTelMakeCallTransfer")
    End Sub

    </SCRIPT>
     
    Grant Schenck, Apr 14, 2005
    #1
    1. Advertising

  2. Of course as soon as I typed this I think I found the problem...

    Specifically, because of my "On Error Resume Next" I was masking the
    problem. Commenting those out give me:

    -----------------------------------
    Application object error 'ASP 0197 : 80004005'
    Disallowed object use
    /LM/W3SVC/1/Root/MyASP/global.asa, line 31
    Cannot add object with apartment model behavior to the application intrinsic
    object.
    -----------------------------------

    So, is this a drop dead issue? Is using STA type VB object not supported?

    If so, can I use VB at all or must I use C++ and build an MTA?

    Thanks, Grant Schenck


    "Grant Schenck" <> wrote in message
    news:...
    > Hello,
    >
    > I posted an this issue before but I'm clearer on what is going on.
    >
    > I have a simple web site with a global.asa and a single .asp file.
    >
    > In global.asa I handle both Application_OnStart and Application_OnEnd (see
    > below.)
    >
    > The ShoreTelMakeCallTransfer object is a simple VB test object which
    > currently just logs class_initialize and class_terminate along with
    > OnStartPage and OnEndPage.
    >
    > When I acess my ASP page, I see the folowing output from my logging:
    >
    > --> Class_Initialize
    > <-- Class_Initialize
    >
    > --> OnStartPage
    > <-- OnStartPage
    >
    > --> OnEndPage
    > <-- OnEndPage
    >
    > --> Class_Terminate
    > <-- Class_Termiante
    >
    > What I don't understand is why Class_Terminate is called?
    >
    > Based on the fact that in Application_OnStart I:
    >
    > set Application("ShoreTelMakeCallTransfer") = ShoreTelMakeCallTransfer
    >
    > Shouldn't that cause the object to stay loaded????
    >
    > Thanks, Grant Schenck
    >
    > -------------------------------------------------------
    > <SCRIPT LANGUAGE=VBScript RUNAT=Server>
    > Option Explicit
    >
    > Sub Application_OnStart
    > On Error Resume Next
    > Dim ShoreTelMakeCallTransfer
    > Application("ShoreTelMakeCallTransfer") = NULL
    > set ShoreTelMakeCallTransfer =
    > Server.CreateObject("STMakeCallTransfer.STObject")
    > set Application("ShoreTelMakeCallTransfer") = ShoreTelMakeCallTransfer
    > End Sub
    >
    > Sub Application_OnEnd
    > On Error Resume Next
    > Dim ShoreTelMakeCallTransfer
    > set ShoreTelMakeCallTransfer = Application("ShoreTelMakeCallTransfer")
    > set Application("ShoreTelMakeCallTransfer") = NULL
    > Application.Contents.Remove("ShoreTelMakeCallTransfer")
    > End Sub
    >
    > </SCRIPT>
    >
    >
    >
     
    Grant Schenck, Apr 14, 2005
    #2
    1. Advertising

  3. Grant Schenck

    Mark Schupp Guest

    start here:

    http://www.aspfaq.com/show.asp?id=2053

    What functions are you trying to make available globally through the object?

    --
    Mark Schupp
    Head of Development
    Integrity eLearning
    www.ielearning.com


    "Grant Schenck" <> wrote in message
    news:...
    > Hello,
    >
    > I posted an this issue before but I'm clearer on what is going on.
    >
    > I have a simple web site with a global.asa and a single .asp file.
    >
    > In global.asa I handle both Application_OnStart and Application_OnEnd (see
    > below.)
    >
    > The ShoreTelMakeCallTransfer object is a simple VB test object which
    > currently just logs class_initialize and class_terminate along with
    > OnStartPage and OnEndPage.
    >
    > When I acess my ASP page, I see the folowing output from my logging:
    >
    > --> Class_Initialize
    > <-- Class_Initialize
    >
    > --> OnStartPage
    > <-- OnStartPage
    >
    > --> OnEndPage
    > <-- OnEndPage
    >
    > --> Class_Terminate
    > <-- Class_Termiante
    >
    > What I don't understand is why Class_Terminate is called?
    >
    > Based on the fact that in Application_OnStart I:
    >
    > set Application("ShoreTelMakeCallTransfer") = ShoreTelMakeCallTransfer
    >
    > Shouldn't that cause the object to stay loaded????
    >
    > Thanks, Grant Schenck
    >
    > -------------------------------------------------------
    > <SCRIPT LANGUAGE=VBScript RUNAT=Server>
    > Option Explicit
    >
    > Sub Application_OnStart
    > On Error Resume Next
    > Dim ShoreTelMakeCallTransfer
    > Application("ShoreTelMakeCallTransfer") = NULL
    > set ShoreTelMakeCallTransfer =
    > Server.CreateObject("STMakeCallTransfer.STObject")
    > set Application("ShoreTelMakeCallTransfer") = ShoreTelMakeCallTransfer
    > End Sub
    >
    > Sub Application_OnEnd
    > On Error Resume Next
    > Dim ShoreTelMakeCallTransfer
    > set ShoreTelMakeCallTransfer = Application("ShoreTelMakeCallTransfer")
    > set Application("ShoreTelMakeCallTransfer") = NULL
    > Application.Contents.Remove("ShoreTelMakeCallTransfer")
    > End Sub
    >
    > </SCRIPT>
    >
    >
    >
     
    Mark Schupp, Apr 14, 2005
    #3
  4. See my response to my own email.

    It looks like you simply can NOT store an STA (VB) COM object in the
    application.

    It sounds like older versions of IIS did allow this. This seems like a
    bogus limitation becasue at least in my case, the object methods are all
    VERY fast and don't block the calling thread in any significant way.

    So, does anyone have any reason to believe that this isn't true or if there
    is anykind of workaround?

    Thanks, Grant Schenck

    "Mark Schupp" <> wrote in message
    news:#...
    > start here:
    >
    > http://www.aspfaq.com/show.asp?id=2053
    >
    > What functions are you trying to make available globally through the

    object?
    >
    > --
    > Mark Schupp
    > Head of Development
    > Integrity eLearning
    > www.ielearning.com
    >
    >
    > "Grant Schenck" <> wrote in message
    > news:...
    > > Hello,
    > >
    > > I posted an this issue before but I'm clearer on what is going on.
    > >
    > > I have a simple web site with a global.asa and a single .asp file.
    > >
    > > In global.asa I handle both Application_OnStart and Application_OnEnd

    (see
    > > below.)
    > >
    > > The ShoreTelMakeCallTransfer object is a simple VB test object which
    > > currently just logs class_initialize and class_terminate along with
    > > OnStartPage and OnEndPage.
    > >
    > > When I acess my ASP page, I see the folowing output from my logging:
    > >
    > > --> Class_Initialize
    > > <-- Class_Initialize
    > >
    > > --> OnStartPage
    > > <-- OnStartPage
    > >
    > > --> OnEndPage
    > > <-- OnEndPage
    > >
    > > --> Class_Terminate
    > > <-- Class_Termiante
    > >
    > > What I don't understand is why Class_Terminate is called?
    > >
    > > Based on the fact that in Application_OnStart I:
    > >
    > > set Application("ShoreTelMakeCallTransfer") = ShoreTelMakeCallTransfer
    > >
    > > Shouldn't that cause the object to stay loaded????
    > >
    > > Thanks, Grant Schenck
    > >
    > > -------------------------------------------------------
    > > <SCRIPT LANGUAGE=VBScript RUNAT=Server>
    > > Option Explicit
    > >
    > > Sub Application_OnStart
    > > On Error Resume Next
    > > Dim ShoreTelMakeCallTransfer
    > > Application("ShoreTelMakeCallTransfer") = NULL
    > > set ShoreTelMakeCallTransfer =
    > > Server.CreateObject("STMakeCallTransfer.STObject")
    > > set Application("ShoreTelMakeCallTransfer") = ShoreTelMakeCallTransfer
    > > End Sub
    > >
    > > Sub Application_OnEnd
    > > On Error Resume Next
    > > Dim ShoreTelMakeCallTransfer
    > > set ShoreTelMakeCallTransfer = Application("ShoreTelMakeCallTransfer")
    > > set Application("ShoreTelMakeCallTransfer") = NULL
    > > Application.Contents.Remove("ShoreTelMakeCallTransfer")
    > > End Sub
    > >
    > > </SCRIPT>
    > >
    > >
    > >

    >
    >
     
    Grant Schenck, Apr 14, 2005
    #4
  5. Grant Schenck

    Mark Schupp Guest

    If I understand the threading issues the problem is that you would end up
    tying every page containing the STA object to a single thread. IIRC you
    could put some STA objects in Application scope in IIS4 but it was a bug not
    a "feature".

    You might be able to fool IIS into thinking your object was FreeThreaded by
    changing the registry but you would be risking crashes if two threads tried
    to access any global data at the same time.

    Again, what are you trying to accomplish with your object? There may be
    alternative methods available.

    --
    --Mark Schupp
    Head of Development
    Integrity eLearning
    www.ielearning.com


    "Grant Schenck" <> wrote in message
    news:...
    > See my response to my own email.
    >
    > It looks like you simply can NOT store an STA (VB) COM object in the
    > application.
    >
    > It sounds like older versions of IIS did allow this. This seems like a
    > bogus limitation becasue at least in my case, the object methods are all
    > VERY fast and don't block the calling thread in any significant way.
    >
    > So, does anyone have any reason to believe that this isn't true or if
    > there
    > is anykind of workaround?
    >
    > Thanks, Grant Schenck
    >
    > "Mark Schupp" <> wrote in message
    > news:#...
    >> start here:
    >>
    >> http://www.aspfaq.com/show.asp?id=2053
    >>
    >> What functions are you trying to make available globally through the

    > object?
    >>
    >> --
    >> Mark Schupp
    >> Head of Development
    >> Integrity eLearning
    >> www.ielearning.com
    >>
    >>
    >> "Grant Schenck" <> wrote in message
    >> news:...
    >> > Hello,
    >> >
    >> > I posted an this issue before but I'm clearer on what is going on.
    >> >
    >> > I have a simple web site with a global.asa and a single .asp file.
    >> >
    >> > In global.asa I handle both Application_OnStart and Application_OnEnd

    > (see
    >> > below.)
    >> >
    >> > The ShoreTelMakeCallTransfer object is a simple VB test object which
    >> > currently just logs class_initialize and class_terminate along with
    >> > OnStartPage and OnEndPage.
    >> >
    >> > When I acess my ASP page, I see the folowing output from my logging:
    >> >
    >> > --> Class_Initialize
    >> > <-- Class_Initialize
    >> >
    >> > --> OnStartPage
    >> > <-- OnStartPage
    >> >
    >> > --> OnEndPage
    >> > <-- OnEndPage
    >> >
    >> > --> Class_Terminate
    >> > <-- Class_Termiante
    >> >
    >> > What I don't understand is why Class_Terminate is called?
    >> >
    >> > Based on the fact that in Application_OnStart I:
    >> >
    >> > set Application("ShoreTelMakeCallTransfer") = ShoreTelMakeCallTransfer
    >> >
    >> > Shouldn't that cause the object to stay loaded????
    >> >
    >> > Thanks, Grant Schenck
    >> >
    >> > -------------------------------------------------------
    >> > <SCRIPT LANGUAGE=VBScript RUNAT=Server>
    >> > Option Explicit
    >> >
    >> > Sub Application_OnStart
    >> > On Error Resume Next
    >> > Dim ShoreTelMakeCallTransfer
    >> > Application("ShoreTelMakeCallTransfer") = NULL
    >> > set ShoreTelMakeCallTransfer =
    >> > Server.CreateObject("STMakeCallTransfer.STObject")
    >> > set Application("ShoreTelMakeCallTransfer") = ShoreTelMakeCallTransfer
    >> > End Sub
    >> >
    >> > Sub Application_OnEnd
    >> > On Error Resume Next
    >> > Dim ShoreTelMakeCallTransfer
    >> > set ShoreTelMakeCallTransfer = Application("ShoreTelMakeCallTransfer")
    >> > set Application("ShoreTelMakeCallTransfer") = NULL
    >> > Application.Contents.Remove("ShoreTelMakeCallTransfer")
    >> > End Sub
    >> >
    >> > </SCRIPT>
    >> >
    >> >
    >> >

    >>
    >>

    >
    >
     
    Mark Schupp, Apr 14, 2005
    #5
  6. At this point I'll play by the rules and write an C++ based MTA. Internally
    it will be using an STA but that should be OK... I believe...

    Also, while were on the subject, the STA uses a windows timer. Do you know
    if ASP->MTA->STA will allow a message pump be available to the STA?
    --
    Grant Schenck

    "Mark Schupp" <> wrote in message
    news:...
    > If I understand the threading issues the problem is that you would end up
    > tying every page containing the STA object to a single thread. IIRC you
    > could put some STA objects in Application scope in IIS4 but it was a bug

    not
    > a "feature".
    >
    > You might be able to fool IIS into thinking your object was FreeThreaded

    by
    > changing the registry but you would be risking crashes if two threads

    tried
    > to access any global data at the same time.
    >
    > Again, what are you trying to accomplish with your object? There may be
    > alternative methods available.
    >
    > --
    > --Mark Schupp
    > Head of Development
    > Integrity eLearning
    > www.ielearning.com
    >
    >
    > "Grant Schenck" <> wrote in message
    > news:...
    > > See my response to my own email.
    > >
    > > It looks like you simply can NOT store an STA (VB) COM object in the
    > > application.
    > >
    > > It sounds like older versions of IIS did allow this. This seems like a
    > > bogus limitation becasue at least in my case, the object methods are all
    > > VERY fast and don't block the calling thread in any significant way.
    > >
    > > So, does anyone have any reason to believe that this isn't true or if
    > > there
    > > is anykind of workaround?
    > >
    > > Thanks, Grant Schenck
    > >
    > > "Mark Schupp" <> wrote in message
    > > news:#...
    > >> start here:
    > >>
    > >> http://www.aspfaq.com/show.asp?id=2053
    > >>
    > >> What functions are you trying to make available globally through the

    > > object?
    > >>
    > >> --
    > >> Mark Schupp
    > >> Head of Development
    > >> Integrity eLearning
    > >> www.ielearning.com
    > >>
    > >>
    > >> "Grant Schenck" <> wrote in message
    > >> news:...
    > >> > Hello,
    > >> >
    > >> > I posted an this issue before but I'm clearer on what is going on.
    > >> >
    > >> > I have a simple web site with a global.asa and a single .asp file.
    > >> >
    > >> > In global.asa I handle both Application_OnStart and Application_OnEnd

    > > (see
    > >> > below.)
    > >> >
    > >> > The ShoreTelMakeCallTransfer object is a simple VB test object which
    > >> > currently just logs class_initialize and class_terminate along with
    > >> > OnStartPage and OnEndPage.
    > >> >
    > >> > When I acess my ASP page, I see the folowing output from my logging:
    > >> >
    > >> > --> Class_Initialize
    > >> > <-- Class_Initialize
    > >> >
    > >> > --> OnStartPage
    > >> > <-- OnStartPage
    > >> >
    > >> > --> OnEndPage
    > >> > <-- OnEndPage
    > >> >
    > >> > --> Class_Terminate
    > >> > <-- Class_Termiante
    > >> >
    > >> > What I don't understand is why Class_Terminate is called?
    > >> >
    > >> > Based on the fact that in Application_OnStart I:
    > >> >
    > >> > set Application("ShoreTelMakeCallTransfer") =

    ShoreTelMakeCallTransfer
    > >> >
    > >> > Shouldn't that cause the object to stay loaded????
    > >> >
    > >> > Thanks, Grant Schenck
    > >> >
    > >> > -------------------------------------------------------
    > >> > <SCRIPT LANGUAGE=VBScript RUNAT=Server>
    > >> > Option Explicit
    > >> >
    > >> > Sub Application_OnStart
    > >> > On Error Resume Next
    > >> > Dim ShoreTelMakeCallTransfer
    > >> > Application("ShoreTelMakeCallTransfer") = NULL
    > >> > set ShoreTelMakeCallTransfer =
    > >> > Server.CreateObject("STMakeCallTransfer.STObject")
    > >> > set Application("ShoreTelMakeCallTransfer") =

    ShoreTelMakeCallTransfer
    > >> > End Sub
    > >> >
    > >> > Sub Application_OnEnd
    > >> > On Error Resume Next
    > >> > Dim ShoreTelMakeCallTransfer
    > >> > set ShoreTelMakeCallTransfer =

    Application("ShoreTelMakeCallTransfer")
    > >> > set Application("ShoreTelMakeCallTransfer") = NULL
    > >> > Application.Contents.Remove("ShoreTelMakeCallTransfer")
    > >> > End Sub
    > >> >
    > >> > </SCRIPT>
    > >> >
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >
     
    Grant Schenck, Apr 14, 2005
    #6
    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:
    494
    Wayne
    Nov 11, 2003
  2. Rashad Rivera

    Why does Application_Start fire twice?

    Rashad Rivera, Apr 26, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    3,774
    Matt Berther
    May 1, 2004
  3. tfs
    Replies:
    3
    Views:
    597
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,135
    Smokey Grindel
    Dec 2, 2006
  5. David Morgan
    Replies:
    2
    Views:
    136
    David Morgan
    Nov 9, 2007
Loading...

Share This Page