Issue with Callback method and maintaining CultureInfo and ASP.Net HttpRuntime
Posted
by
Little Larry Sellers
on Stack Overflow
See other posts from Stack Overflow
or by Little Larry Sellers
Published on 2009-07-01T16:54:06Z
Indexed on
2010/12/23
0:54 UTC
Read the original article
Hit count: 258
Hi All,
Here is my issue. I am working on an E-commerce solution that is deployed to multiple European countries. We persist all exceptions within the application to SQL Server and I have found that there are records in the DB that have a DateTime in the future!
We define the culture in the web.config, for example pt-PT, and the format expected is DD-MM-YYYY.
After debugging I found the issue with these 'future' records in the DB is because of Callback methods we use. For example, in our Caching architecture we use Callbacks, as such -
CacheItemRemovedCallback ReloadCallBack = new CacheItemRemovedCallback(OnRefreshRequest);
When I check the current threads CultureInfo, on these Callbacks it is en-US instead of pt-PT and also the HttpContext is null. If an exception occurs on the Callback our exception manager reports it as MM-DD-YYYY and thus it is persisted to SQL Server incorrectly.
Unfortunately, in the exception manager code, we use DateTime.Now, which is fine if it is not a callback. I can't change this code to be culture specific due to it being shared across other verticals.
So, why don't callbacks into ASP.Net maintain context? Is there any way to maintain it on this callback thread? What are the best practices here?
Thanks.
© Stack Overflow or respective owner