Cache loss in ASP. NET

Source: Internet
Author: User
This blog Program During use, check the error log and find the following errors:

< Erroritem >
< Date > 18:07:26 error file: http://xianfen.net/Default.aspx </ Date >
< Message > Error message: an exception of the type "system. Web. httpunhandledexception" is thrown. Internal error message: the instance of the object has not been referenced. </ Message >
</ Erroritem >
< Erroritem >
< Date > 18:07:27 error file: http://xianfen.net/Default.aspx </ Date >
< Message > Error message: an exception of the type "system. Web. httpunhandledexception" is thrown. Internal error message: the instance of the object has not been referenced. </ Message >
</ Erroritem >
< Erroritem >
< Date > 21:01:47 error file: http://www.xianfen.net/Category5_1.aspx? Classid = 5 & Amp; Page = 1 </ Date >
< Message > Error message: an exception of the type "system. Web. httpunhandledexception" is thrown. Internal error message: the instance of the object has not been referenced. </ Message >
</ Erroritem >
< Erroritem >
< Date > 9:21:02 error file: http://www.xianfen.net/Archive200712.aspx? Year = 2007 & Amp; Month = 12 </ Date >
< Message > Error message: an exception of the type "system. Web. httpunhandledexception" is thrown. Internal error message: the instance of the object has not been referenced. </ Message >
</ Erroritem >

...

Many "instances where object references are not set to objects .", Review each row of programs carefully and no empty objects are found. In desperation, debug on the local machine and find exceptionsCodeSection:

Public Static String Blogtitle
{
Get
{
If (Httpcontext. Current. cache [ " Blogtitle " ] = Null )
{
Httpcontext. Current. cache [ " Blogtitle " ] = Configurationmanager. deleettings [ " Blogtitle " ];
}

ReturnHttpcontext. Current. cache ["Blogtitle"]. Tostring ();//An exception is thrown here. "The object reference is not set to the object instance"
}
}

To improve performance, this blog system uses multiple caches, but does it check whether it is empty every time cache data is retrieved? I had to go to Google and found that I encountered the same problem. The original cache will be removed when the memory is insufficient. It seems that the memory of the virtual space is very tight, and the cache I just set is removed!
Replace the cache with application:

Public Static String Blogtitle
{
Get
{
If (Httpcontext. Current. application [ " Blogtitle " ] = Null )
{
Httpcontext. Current. application [ " Blogtitle " ] = Configurationmanager. deleettings [ " Blogtitle " ];
}< P>

return httpcontext. current. application [ " blogtitle " ]. tostring ();
}< BR >}< br>

solution!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.