0

我开发了一个 HttpModule,用于PreInit在登录用户的个人资料中为页面分配主题。但似乎配置文件在我访问它时没有初始化。是否有一个特定的事件,之后我应该访问类似于事件后访问页面 cotnrolls 的用户的个人资料Init。顺便说一句,我在 ASP.NET 2.0 和自定义配置文件提供程序实现上运行。

 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;

上面的方法PreInit在我的应用程序的每个页面的舞台上执行。

4

1 回答 1

0

它需要在类的 OnPreInit 方法中进行初始化。

覆盖 void OnPreInit(EventArgs e);

对于方法执行,请点击此链接,它简要介绍了何时调用 asp.net 生命周期的方法。

于 2012-03-19T06:17:51.277 回答