I recently set up a new instance of my personal website on the same server as the actual site. The new instance is a "latest" configuration so it's got all the new features of the latest build I'm working on. The latest build I've switched the Target Framework to 3.5 from 2.0 as the only really major change as fas as the compiled items go.
On all member pages and some other pages and some user controls I call one or both of these two items, and each are failing and causing an Object reference not set to an instance of an object
, error. But not on every page!
public static string CurrentUserName
{
get
{
string userName = "";
if (HttpContext.Current.User.Identity.IsAuthenticated)
userName = HttpContext.Current.User.Identity.Name;
return userName;
}
}
public static string CurrentUserID
{
get
{
string userID = "";
if (HttpContext.Current.User.Identity.IsAuthenticated) //Line 39
{
MembershipUser user = Membership.GetUser();
userID = user.ProviderUserKey.ToString();
}
return userID;
}
}
With the stack trace being:
[NullReferenceException: Object reference not set to an instance of an object.]
isClasses.BizObjects.get_CurrentUserID() in C:\My Dropbox\Trunk\Classes\BizObjects.cs:39
TheImageStore_Profile..ctor() in w:\dev\Member\Profile.aspx.cs:9
ASP.member_profile_aspx..ctor() in c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\faba6118\7249af47\App_Web_profile.aspx.48943a5b.w8t4pvz5.0.cs:0
__ASP.FastObjectFactory_app_web_profile_aspx_48943a5b_w8t4pvz5.Create_ASP_member_profile_aspx() in c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\faba6118\7249af47\App_Web_profile.aspx.48943a5b.w8t4pvz5.2.cs:0
System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +119
System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +33
System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String requestType, String virtualPath, String path) +37
System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +307
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
But mind you, this is only happening in IIS 7 on Server 2008, the site is working perfectly from Visual Studio 2008. I've even attached the main website in IIS to this directory and it does the same thing. How is it possible to have this happen, and what could be the cause?
Just for kicks I changed the Target Framework back to 2.0 and it's still causing the same issue. Also this seems to be happening with or without the visitor being logged in, and not just on member pages.