Under what context Application events run in Global.asax

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Under what context Application events run in Global.asax

    (I am running .NET Framework 1.1)

    I have a timer(System.Timers.Timer) running in my Global.asax page. In
    the timer.elapsed event I am trying to access an object I stored in
    the Cache.
    HttpContext.Current.Cache("xxx"). I am getting an error saying that
    HttpContext.Current is nothing.

    I also tried to check HttpContext.Current.User.Identity.Name and got
    an error and it says HttpContext.Current.User is nothing.

    I tried to get HttpContext.Current.User.Identity.Name in
    Application_onstart event and got the same error -
    HttpContext.Current.User is nothing.

    Can someone please tell me where I am going wrong.

    It is very critical for my project to access the cache object in the
    timer.elapsed event.

    Thanks
    Ram
    Ram Guest

  2. Similar Questions and Discussions

    1. global.asax
      Hi all! I've created a simple aspx application and when I run it locally on my pc all works fine. If I move it on the web server I get the...
    2. Name of events in Global.asax
      Hi. Reading the docs about the Global.asax events I noticed the names used on the help are not the same on the file. For example, the docs talk...
    3. global.asax problem
      Hi all! I've created a simple aspx application and when I run it locally on my pc all works fine. If I move it on the web server I get the...
    4. Global Error handling in Applicatio_Error() of Global.asax
      Hi all, For a web application if we are using web farm, and if i want to do Global Error handling can i use Applicatio_Error() method in...
    5. What is Global.asax?
      It's the class file definition code for the Session and Application events - if you have anything that should be done when a user first connects or...
  3. #2

    Default Re: Under what context Application events run in Global.asax

    Did you try HttpRuntime.Cache?

    Hopefully that is initialized by then.

    I don't think you can expect to get the context object in a timer event as
    there may not be a request in the pipeline.

    Joe K.

    "Ram" <rampabbaraju@yahoo.com> wrote in message
    news:fee5cd7f.0402110345.5e7b98f5@posting.google.c om...
    > (I am running .NET Framework 1.1)
    >
    > I have a timer(System.Timers.Timer) running in my Global.asax page. In
    > the timer.elapsed event I am trying to access an object I stored in
    > the Cache.
    > HttpContext.Current.Cache("xxx"). I am getting an error saying that
    > HttpContext.Current is nothing.
    >
    > I also tried to check HttpContext.Current.User.Identity.Name and got
    > an error and it says HttpContext.Current.User is nothing.
    >
    > I tried to get HttpContext.Current.User.Identity.Name in
    > Application_onstart event and got the same error -
    > HttpContext.Current.User is nothing.
    >
    > Can someone please tell me where I am going wrong.
    >
    > It is very critical for my project to access the cache object in the
    > timer.elapsed event.
    >
    > Thanks
    > Ram

    Joe Kaplan \(MVP - ADSI\) Guest

  4. #3

    Default Re: Under what context Application events run in Global.asax

    Joe,

    Thanks for your response.

    I tried HttpRuntime.Cache, and it did not solve my problem.

    I will explain what I am trying to do.

    I have a class A. In that class I am creating a COM(remote) object in
    the constructor(using createobject) and storing it in a private
    variable(m_comObject). When I am done with using A object in my ASPX
    page, I will call a method in the A class, that executes
    Marshal.ReleaseComObject(m_comObject) to release the COM reference.

    Because creating the COM object takes lot of time(20 seconds) I am
    caching the A object like by doing Context.Current.Cache("A").

    I am running a timer in my Global.asax. In the Timer Elapsed event, I
    find when the connected users are zero (I can not use Application on
    end event), I want to get the A object from the cache, release the COM
    reference by calling ReleaseCOMObject method in the class and then
    remove the object from cache.

    When I was using HttpContext.Current.Cache, I was not able to access
    it from Timer elapsed event. But when I used HTTPRuntime.Cache, I was
    able to access the cache, get the object and call the method in the
    class. But it is not removing the COM reference. I can see the COM
    object still open from the task manager. There is no problem if the
    call is made from an ASPX page, it is not working from the Timer.

    There is one more class similar to A i.e., B. When I create the object
    B from an ASPX page, there is no problem. If I try to create it from
    Timer elapsed event, it throws an error "Can not create ActiveX
    component." This happens when the COM server is in a remote machine.
    If it is local, COM object creation has no problem.

    I thought ASPX pages run under a user context and Application events
    don't. I think this is the problem.

    Please advise me.


    "Joe Kaplan \(MVP - ADSI\)" <joseph.e.kaplan@removethis.accenture.com> wrote in message news:<OOG9EDR8DHA.1632@TK2MSFTNGP12.phx.gbl>...
    > Did you try HttpRuntime.Cache?
    >
    > Hopefully that is initialized by then.
    >
    > I don't think you can expect to get the context object in a timer event as
    > there may not be a request in the pipeline.
    >
    > Joe K.
    Ram Guest

  5. #4

    Default Re: Under what context Application events run in Global.asax

    Very interesting. I doubt I can help you more. I was aware that you can
    get an instance of the Cache from the HttpRuntime, but it sounds like there
    may be something in the initialization of your COM object that may be at the
    heart of the problem. Cross posting to the interop group may help. I know
    nearly nothing about DCOM.

    Is it possible that the issue is related to the identity the object is
    instantiated under? It would be interesting to compare
    Thread.CurrentThread.CurrentPrincipal.Identity.Nam e and
    System.Security.Principal.WindowsIdentity.GetCurre nt().Name in both places
    and see if they are the same. That will tell you your managed and unmanaged
    security contexts.

    You might also consider checking the return value of ReleaseComObject and
    make sure it is returning nothing. If it returns nothing, then that object
    should be released! If not, the reference count has not been decremented
    all the way (according to the docs that is...).

    Good luck. I hope you can find a solution.

    Joe K.

    "Ram" <rampabbaraju@yahoo.com> wrote in message
    news:fee5cd7f.0402120446.79bf868@posting.google.co m...
    > Joe,
    >
    > Thanks for your response.
    >
    > I tried HttpRuntime.Cache, and it did not solve my problem.
    >
    > I will explain what I am trying to do.
    >
    > I have a class A. In that class I am creating a COM(remote) object in
    > the constructor(using createobject) and storing it in a private
    > variable(m_comObject). When I am done with using A object in my ASPX
    > page, I will call a method in the A class, that executes
    > Marshal.ReleaseComObject(m_comObject) to release the COM reference.
    >
    > Because creating the COM object takes lot of time(20 seconds) I am
    > caching the A object like by doing Context.Current.Cache("A").
    >
    > I am running a timer in my Global.asax. In the Timer Elapsed event, I
    > find when the connected users are zero (I can not use Application on
    > end event), I want to get the A object from the cache, release the COM
    > reference by calling ReleaseCOMObject method in the class and then
    > remove the object from cache.
    >
    > When I was using HttpContext.Current.Cache, I was not able to access
    > it from Timer elapsed event. But when I used HTTPRuntime.Cache, I was
    > able to access the cache, get the object and call the method in the
    > class. But it is not removing the COM reference. I can see the COM
    > object still open from the task manager. There is no problem if the
    > call is made from an ASPX page, it is not working from the Timer.
    >
    > There is one more class similar to A i.e., B. When I create the object
    > B from an ASPX page, there is no problem. If I try to create it from
    > Timer elapsed event, it throws an error "Can not create ActiveX
    > component." This happens when the COM server is in a remote machine.
    > If it is local, COM object creation has no problem.
    >
    > I thought ASPX pages run under a user context and Application events
    > don't. I think this is the problem.
    >
    > Please advise me.
    >
    >
    > "Joe Kaplan \(MVP - ADSI\)" <joseph.e.kaplan@removethis.accenture.com>
    wrote in message news:<OOG9EDR8DHA.1632@TK2MSFTNGP12.phx.gbl>...
    > > Did you try HttpRuntime.Cache?
    > >
    > > Hopefully that is initialized by then.
    > >
    > > I don't think you can expect to get the context object in a timer event
    as
    > > there may not be a request in the pipeline.
    > >
    > > Joe K.

    Joe Kaplan \(MVP - ADSI\) Guest

  6. #5

    Default Re: Under what context Application events run in Global.asax

    Joe,

    Thanks for the info you provided me.

    System.Security.Principal.WindowsIdentity.GetCurre nt().Name is showing
    MACHINENAME/ASPNET in the timer and when the object is created and
    cached it is MACHINENAME/LOGGEDONUSERNAME.

    I think this is the problem and I need to impersonate as
    MACHINENAME/LOGGEDONUSERNAME

    "Joe Kaplan \(MVP - ADSI\)" <joseph.e.kaplan@removethis.accenture.com> wrote in message news:<OcR7fBY8DHA.3008@TK2MSFTNGP09.phx.gbl>...
    > Very interesting. I doubt I can help you more. I was aware that you can
    > get an instance of the Cache from the HttpRuntime, but it sounds like there
    > may be something in the initialization of your COM object that may be at the
    > heart of the problem. Cross posting to the interop group may help. I know
    > nearly nothing about DCOM.
    >
    > Is it possible that the issue is related to the identity the object is
    > instantiated under? It would be interesting to compare
    > Thread.CurrentThread.CurrentPrincipal.Identity.Nam e and
    > System.Security.Principal.WindowsIdentity.GetCurre nt().Name in both places
    > and see if they are the same. That will tell you your managed and unmanaged
    > security contexts.
    >
    > You might also consider checking the return value of ReleaseComObject and
    > make sure it is returning nothing. If it returns nothing, then that object
    > should be released! If not, the reference count has not been decremented
    > all the way (according to the docs that is...).
    >
    > Good luck. I hope you can find a solution.
    >
    > Joe K.
    >
    Ram Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139