c# - ASP.NET Random error: Server Error in '/' Application. Object reference not set to an instance of an object -
i building asp.net webpage allow register new account inside crm 2011. seems work, after around half hour code stops working, without touching it. page shows
"server error in '/' application. object reference not set instance of object."
republishing code solves it, happening under hood? limited time makes me think might related login issue, login performed when page loaded credentials stored in web.config file.
in aspx page have
void page_load ( object sender , eventargs e ) { loadvalues ( sender , e ); if (!ispostback) { session["pagerefresh"] = system.datetime.now.tostring(); } } protected void page_prerender(object sender, eventargs e) { viewstate["pagerefresh"] = session["pagerefresh"]; stateview = datetime.parse(session["pagerefresh"].tostring()); }
i using ispostback in 2 places:
if ((statvar.firstexec == true || (datetime.parse(session["pagerefresh"].tostring()) != stateview)) && !ispostback) contactdropdownlist.items.add ( new listitem ( " " , "0" ) ); if ( (statvar.firstexec == true || (datetime.parse(session["pagerefresh"].tostring()) != stateview)) && !ispostback) contactdropdownlist.items.add ( new listitem ( value , indstring ) );
your prerender uses session directly without checking if null. sessions meant expire automatically after preset duration , default duration 20 mins. try code below
protected void page_prerender(object sender, eventargs e) { if(session["pagerefresh"] != null) { viewstate["pagerefresh"] = session["pagerefresh"]; stateview = datetime.parse(session["pagerefresh"].tostring()); } }
Comments
Post a Comment