Ask a Question related to ASP.NET Security, Design and Development.
-
Ram #1
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
-
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... -
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... -
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... -
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... -
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... -
Joe Kaplan \(MVP - ADSI\) #2
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
-
Ram #3
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
-
Joe Kaplan \(MVP - ADSI\) #4
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...wrote in message news:<OOG9EDR8DHA.1632@TK2MSFTNGP12.phx.gbl>...> 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>as> > 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> > there may not be a request in the pipeline.
> >
> > Joe K.
Joe Kaplan \(MVP - ADSI\) Guest
-
Ram #5
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



Reply With Quote

