ASP.NET 2.0: using Cache in Global.asax

R

R.A.M.

I am learning ASP.NET.
In Global.asax file I have such code:

....
<%@ Import Namespace="System.Web.Caching" %>
....
void Application_Error(object sender, EventArgs e)
{
Exception ex = (Exception) Server.GetLastError();
if (ex != null)
Cache["Problem"] = ex.Message; // HERE PROBLEM
else
Cache["Problem"] = ""; // HERE PROBLEM
Server.Transfer("Problem.html");
}
....

The problem-error is: "'System.Web.Caching.Cache' is a 'type' but is
used like a variable."
How to write it correctly?
Thank you!!!
/RAM/
 
B

Brock Allen

You don't want to write code this way because the Cache is a shared resource
and it's possible that 2 different requests are both executing in your Error
event handler at the same time. This leads to the possibility that your problem.html
gets the errors mixed up. Put the error into HttpContext.Items collection
to pass it to another page.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top