I am building an ASP.NET webpage that will allow to register a new Account inside CRM 2011. Everything seems to work, but after around half an hour the code stops working, without anyone touching it. The page shows a
"Server Error in '/' Application. Object reference not set to an instance of an object."
Republishing the code solves it, but what is happening under the hood? The limited time makes me think it might be related to a login issue, but the login is performed when the page is loaded with credentials stored in the Web.config file.
In the ASPX page I 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 am using IsPostBack in two 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 ) );