I recently wrote a method that tracks unexpected errors. This method is called in the global.asax file in the Application_Error event. I pass the .Net Profile object to this method. For some reason that I have yet to determine, from time to time, some
of the fields in the Profile object have null values when referenced in the Application_Error event. This is an asp.net 2.0 intranet application where all users have to log in.
The profile object and its properties has always been available to every one of my pages. I never had a problem with it. For some reason, the properties lose their value after the user logs in and an unexpected error happens. To compond the problem, the
profile properties sometimes have values and are sometimes null.
I have no clue as to why this is happening. Could this have something to do with the page life cycle? In other words, maybe the error happens before the page event that gives you access to the profile? Does anyone know what event that would be?
Any help would be much appreciated. Below are snippets from
My web.config
the code from the LoggedIn event of my login form
the global.asax file
the signature of the method where the profile is periodically null
NewToDotNet
Participant
1052 Points
734 Posts
Profile object is null from time to time
Nov 09, 2011 06:43 PM|LINK
I recently wrote a method that tracks unexpected errors. This method is called in the global.asax file in the Application_Error event. I pass the .Net Profile object to this method. For some reason that I have yet to determine, from time to time, some of the fields in the Profile object have null values when referenced in the Application_Error event. This is an asp.net 2.0 intranet application where all users have to log in.
The profile object and its properties has always been available to every one of my pages. I never had a problem with it. For some reason, the properties lose their value after the user logs in and an unexpected error happens. To compond the problem, the profile properties sometimes have values and are sometimes null.
I have no clue as to why this is happening. Could this have something to do with the page life cycle? In other words, maybe the error happens before the page event that gives you access to the profile? Does anyone know what event that would be?
Any help would be much appreciated. Below are snippets from
Thanks so much. This is driving me crazy.
My web.config has the following code.
<profile enabled="true" defaultProvider="SqlProvider">
<providers>
<clear/>
<add name="SqlProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="CompanyNameConnectionString"/>
</providers>
<properties>
<add name="UserID" type="int"/>
<add name="LocationCode" type="String"/>
<add name="LocationDescription" type="String"/>
<add name="URL" type="String"/>
<add name="PageTitle" type="String"/>
<add name="PermissionCode" type="String"/>
<add name="PermissionDescription" type="String"/>
<add name="Message" type="String"/>
<add name="DepartmentCode" type="int"/>
<add name="MenuID" type="int"/>
</properties>
</profile>
When the user logs in, I run the following code in the LoggedIn event to load the profile.
ProfileCommon p = Profile.GetProfile(UserLogin.UserName);
if (p == null)
{
throw new Exception("Profile was Not Created for " + UserLogin.UserName);
}
p.UserID = DGUser.UserID;
p.LocationCode = location.LocationCode;
p.LocationDescription = location.Description;
p.DepartmentCode = DGUser.DepartmentCodes.DepartmentCode;
p.MenuID = Globals.MenuItems.DefaultPage;
p.Save();
The global.asax
void Application_Error(object sender, EventArgs e)
{
CompanyName.Services.ErrorHandlerService.HandleUnExpectedError(Profile);
}
The Error Handler Service
public static void HandleUnExpectedError(ProfileCommon profile)