I have a header control that I include in my .aspx page. In this control, I'm trying to retrieve a cookie value and store it into a string, but I am receiving an "Object reference not set to an instance of an object." error. Below is the code. Any help is appreciated. Thanks.
.aspx page:
C# code:
.aspx page:
Code:
<%@ Page Language="C#" AutoEventWireUp=true CodeFile="OrderAdmin.aspx.cs" Inherits="_Default" %>
<%@ Reference Control="/custom/applications/shared_controls/reasonEntry.ascx" %>
<%@ Register tagprefix="RBARC" tagname="Header" src="/custom/applications/shared_controls/header.ascx" %>
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<!-- START OrderAdmin.aspx -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="../appStyles.css" type="text/css" />
<link href="/custom/applications/Yahoo_Tools_2_5_0/yui/build/calendar/assets/calendar.css" rel="stylesheet" type="text/css" media="screen" />
<title>Order Administration</title>
</head>
<body>
<RBARC:Header ID="pageHeader" runat="server" />
<!--rest of code here-->
</body>
</html>
Code:
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
public partial class Header : System.Web.UI.UserControl
{
//Secure is a proprietary object of Vandamme Associates
//http://www.vandamme.com
//constant value
const string STAFF_CODE = "RC_STAFF";
const string EXIT_CODE = "EXIT";
private void Page_Init(object sender, System.EventArgs e)
{
//retrieves encrypted user ID and decrypts if not already created
if (Session["UserID"] == null)
{
Secure decryptUID = new Secure();
string encryptedValue = Request.Cookies["UserID"].Value;
Session["UserID"] = decryptUID.Decrypt(encryptedValue);
encryptedValue = String.Empty;
}
if (Session["RC_User_Level"] == null)
{
CDataAccess getSelectionCodes = new CDataAccess(ConfigurationSettings.AppSettings["ConnectionStringiMIS"]);
getSelectionCodes.OpenConnection();
getSelectionCodes.SelectData("Custom_GetCodes '" + Session["UserID"] + "'");
if (getSelectionCodes.ReadNextRow())
{
Session["RC_User_Level"] = getSelectionCodes.GetString("INTERNET_SELECTION_CODES");
}
getSelectionCodes.CloseConnection();
}
}
//rest of code here
}
Comment