Search code examples
asp.neteventsthemeshttpmoduleprofiles

When is UserProfile initialized


I developed a HttpModule for assigning themes to pages during it's PreInit event from Profile of the logged in user. But seems the profile is not initialized at the time i access it. Is there a specific event after which i should access Profile for a user similar to access page cotnrols after Init event. btw i am running on ASP.NET 2.0 and Custom Profile Provider implementation.

 public void CurrentPageOnPreInit(object sender, EventArgs e)
    {
        //Get the page currently requested
        Page currentPage = (Page)sender;

        //Get the user profile
        ProfileCommon userProfile = HttpContext.Current.Profile as ProfileCommon;


            //check if user profile has theme set
            if (userProfile != null && !string.IsNullOrEmpty(userProfile.Theme))
            {
                //retrieve from profile
                currentPage.Theme = userProfile.Theme;

where the above method executes on PreInit stage of each page on my application.


Solution

  • It needs to initialized in the OnPreInit method of the class.

    override void OnPreInit(EventArgs e);

    For methods execution follow this link it give brief about when which method will call asp.net life cycle.