M
Max2006
Hi,
I am debugging a very simple, web project in VS2008, IIS7. The application
uses AbsoluteExpiration timeout in Cache.Insert.
The application works fine except when a debugger is attached to it. Even a
single break point on a line of code crashes the application. The problem is
when a debugger is attached and the "onRemoveCallback" method is called,
HttpContext.Current is null.
Here is the code that reproduces the problem. If you have breakpoint
anywhere in the application, RefreshHelpContentsUrlCache method gives
NullReferenceException because HttpContext.Current is null.
Is there any way to make it work when VS2008 debugger is engaged?
Any help would be appreciated,
Max
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Caching;
namespace WebLabIIS
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = CachedData;
}
public static string CachedData
{
get
{
if (HttpContext.Current.Cache["CachedData"] == null)
RefreshCache(null, null,
CacheItemRemovedReason.Expired);
return HttpContext.Current.Cache["CachedData"] as string;
}
}
private static void RefreshCache(String key, object value,
CacheItemRemovedReason removedReason)
{
string data = "Time: " + DateTime.Now.ToString();
HttpContext.Current.Cache.Insert(
"CachedData",
data,
null,
System.DateTime.Now.AddSeconds(1),
Cache.NoSlidingExpiration,
CacheItemPriority.Default,
RefreshCache);
}
}
}
I am debugging a very simple, web project in VS2008, IIS7. The application
uses AbsoluteExpiration timeout in Cache.Insert.
The application works fine except when a debugger is attached to it. Even a
single break point on a line of code crashes the application. The problem is
when a debugger is attached and the "onRemoveCallback" method is called,
HttpContext.Current is null.
Here is the code that reproduces the problem. If you have breakpoint
anywhere in the application, RefreshHelpContentsUrlCache method gives
NullReferenceException because HttpContext.Current is null.
Is there any way to make it work when VS2008 debugger is engaged?
Any help would be appreciated,
Max
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Caching;
namespace WebLabIIS
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = CachedData;
}
public static string CachedData
{
get
{
if (HttpContext.Current.Cache["CachedData"] == null)
RefreshCache(null, null,
CacheItemRemovedReason.Expired);
return HttpContext.Current.Cache["CachedData"] as string;
}
}
private static void RefreshCache(String key, object value,
CacheItemRemovedReason removedReason)
{
string data = "Time: " + DateTime.Now.ToString();
HttpContext.Current.Cache.Insert(
"CachedData",
data,
null,
System.DateTime.Now.AddSeconds(1),
Cache.NoSlidingExpiration,
CacheItemPriority.Default,
RefreshCache);
}
}
}