HttpContext.Current.Session NullReferenceException on IIS6

Topics: Web Client Software Factory, User Forum
Jun 21, 2007 at 10:40 AM
Hi!

I'm having a problem which is not clear to me.
When I'm running the WebUI on Visual Studio 2005 default web server, I don’t have any problem with accessing session variables, as this example at ViewPresenterQuickStart:

public virtual Customer CurrentCustomer
{
get
{
Customer current = HttpContext.Current.Session"CurrentCustomer" as Customer;
if (current == null)
{
current = GetNextCustomer();
HttpContext.Current.Session"CurrentCustomer" = current;
}
return current;
}
private set
{
HttpContext.Current.Session"CurrentCustomer" = value;
}
}

When I run the same project on IIS6, Windows Server 2003 SP1 Standard, I simply get a NullReferenceException at this line:

Customer current = HttpContext.Current.Session"CurrentCustomer" as Customer;

System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="ViewPresenterQuickStart.ViewPresenter.Customers"
StackTrace:
at ViewPresenterQuickStart.ViewPresenter.Customers.CustomersController.get_CurrentCustomer()
at ViewPresenterQuickStart.ViewPresenter.Customers.Views.ApproveCustomerViewPresenter.OnViewLoaded()
at ApproveCustomerView.Page_Load(Object sender, EventArgs e)
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Does anyone can help me? Am I missing anything?

Thanks!

Miguel Figueiredo