Alert reader Gustavo Garcia emailed me recently with a small bug he found in my URL Rewriting in ASP.NET article:
I think the code:
if (HttpContext.Current.Cache["RewriterConfig"] == null)
HttpContext.Current.Cache.Insert("RewriterConfig",
ConfigurationSettings.GetConfig("RewriterConfig"));
return (RewriterConfiguration)
HttpContext.Current.Cache["RewriterConfig"]; //Could return NULL?!?!?!?
could produce race conditions, because the Cache could be freed between if
and return.
RewriterConfiguration config =
(RewriterConfiguration)HttpContext.Current.Cache["RewriterConfig"];
if (config == null)
{
config = ConfigurationSettings.GetConfig("RewriterConfig");
HttpContext.Current.Cache.Insert("RewriterConfig", config);
}
return config;
Best regards, and thank you for your article.
Good catch, Gustavo. This problem is discussed with a good explanation in Scott Cate's blog entry: Steve Smith's Awesome Caching Pattern.
Speaking of URL rewriting in ASP.NET, the #1 question I get is with regards to mapping all requests to the aspnet_isapi.dll ISAPI Extension. The blog engine software that I use to run this blog - .Text (or Community Server :: Blogs, as it will be called) - heavily utilizes URL rewriting and provides an option where all incoming requests can be mapped to the ASP.NET engine. So why not turn to Scott Watermasysk - creator of .Text - for some explanation on this? Scott recently posted an entry on some issues with mapping all requests to the ASP.NET process, including tasks you'll have to do once this mapping is made.