locked
httpModule not working after moving from net2 to net3.5 RRS feed

  • Question

  • User758552382 posted

    My development computer crashed a few weeks back. I took this as the perfect opportunity to upgrade my developmental tools as well as migrate my web app from .net 2 to .net 3.5.

    My question deals with themes and calling themes from an httpmodule.

    THis is my entry in my web.config

     

    <httpModules>
    	<add name="ThemeSelector" type="ThemeSelector"/>
    	<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </httpModules>


    "ThemeSelector" is a .cs file located in my App_Code folder that controls which theme is used for the particular page based on a number of things using a pre_init funtion.

     

    Since the migration it looks to me like the web app is not calling ThemeSelector at the pre_init stage of page load. In short, my theme is not loading. In fact no theme is loading at all.


    This worked perfect when my old computer was operating and in the .net 2 environment, but now it does not.

     

    Has something changed? do i need to modify the webconfig? i am just not familier enough with 3.5 right now to understand that part.

     

    for reference (ThemeSelector.cs):

    using System;
    using System.Web;
    using System.Web.UI;
    using MajorMadness.controls;
    using System.Web.Security;
    
    public class ThemeSelector : IHttpModule
    {
        public void Dispose() { }
    
        public void Init(HttpApplication context)
        {
            // make sure this module is called whenever a handler has been resolved.
            context.PostMapRequestHandler += PostMapRequestHandler;
        }
    
        void PostMapRequestHandler(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;
            Page p = app.Context.Handler as Page;
            if (p != null)
            {
                // if it is a page; make sure this module is called on preinit.
                p.PreInit += PagePreInit;
            }
        }
    
        void PagePreInit(object sender, EventArgs e)
        {
            // here we can set the theme and the masterpage
            Page p = (Page)sender;
    
            // if there is not an authenticated user base theme off of domain
            if (!p.User.Identity.IsAuthenticated)
            {
                //If subdomain is 'www' and it is not 'localhost' or 'www.fantasygolfmajormadness.com'
                if (utilities.GetSubDomain(p.Request.Url.ToString()) == "www" &&
                            p.Request.Url.Host != "localhost" &&
                            p.Request.Url.Host != "cgm22" &&
                            p.Request.Url.Host != "www.FantasyGolfMajorMadness.com" )
                {
                    if (utilities.queryClient(p.Request.Url.Host, "domain", "active") == "1" || utilities.queryClient(p.Request.Url.Host, "domain", "active") == "True")
                    {
                        if (p.Request.QueryString.Count != 0 && RequestParam("themeId", p).Length >= 1)
                        {
                            p.MasterPageFile = "~/MasterPages/" + utilities.queryClient(p.Request["themeId"], "themeName", "masterPageFile");
                            p.Theme = p.Request["themeId"];
                        }
                        else
                        {
                            p.MasterPageFile = "~/MasterPages/" + utilities.queryClient(p.Request.Url.Host, "domain", "masterPageFile");
                            p.Theme = utilities.queryClient(p.Request.Url.Host, "domain", "themeName");
                        }
                    }
                    else
                    {
                        p.Response.Redirect("FantasyGolf.htm");
                    }
                }
    
                //If subdomain does not have 'www' and it is not 'localhost' or 'www.fantasygolfmajormadness.com'
                else if (utilities.GetSubDomain(p.Request.Url.ToString()) != "www" &&
                            p.Request.Url.Host != "localhost" &&
                            p.Request.Url.Host != "cgm22" &&
                            p.Request.Url.Host != "FantasyGolfMajorMadness.com")
                {
                    if (p.Request.QueryString.Count != 0 && RequestParam("themeId", p).Length >= 1)
                    {
                        p.MasterPageFile = "~/MasterPages/" + utilities.queryClient(p.Request["themeId"], "themeName", "masterPageFile");
                        p.Theme = p.Request["themeId"];
                    }
                    else
                    {
                        p.MasterPageFile = "~/MasterPages/" + utilities.queryClient(p.Request.Url.Host, "REPLACE(domain,'www.','')", "masterPageFile");
                        p.Theme = utilities.queryClient(p.Request.Url.Host, "REPLACE(domain,'www.','')", "themeName");
                    }
                }
    
                //Else Default to General Theme
                else
                {
                        // define Theme and MasterPage
                        if (p.Request.QueryString.Count != 0 && RequestParam("themeId", p).Length >= 1)
                        {
                            p.MasterPageFile = "~/MasterPages/" + utilities.queryClient(p.Request["themeId"], "themeName", "masterPageFile");
                            p.Theme = p.Request["themeId"];
                        }
                        else
                        {
                            p.Theme = "General";
                            p.MasterPageFile = "~/MasterPages/General.Master";
                        }
                }
            }
    
            //If there is an authenticated user use User's Client Theme
            else
            {
                //if (utilities.queryClient(p.Request.Url.Host, "domain", "active") == "1" || utilities.queryClient(p.Request.Url.Host, "domain", "active") == "True")
                //{
                    if (p.Request.QueryString.Count != 0 && RequestParam("themeId",p).Length >= 1)
                    {
                        p.MasterPageFile = "~/MasterPages/" + utilities.queryClient(p.Request["themeId"], "themeName", "masterPageFile");
                        p.Theme = p.Request["themeId"];
    
                    }
                    else
                    {
                        // query Client ID# from user's profile
                        string CID = utilities.queryUserProfile(p.User.Identity.Name, "CID");
    
                        // query themeName and masterPageFile based on user's client membership
                        string themeName = utilities.queryClient(CID, "themeName");
                        string masterPage = utilities.queryClient(CID, "masterPageFile");
    
                        // define Theme and MasterPage
                        p.Theme = themeName;
                        p.MasterPageFile = "~/MasterPages/" + masterPage;
                    }
                /**}
                //else
                //{
                //    p.Response.Redirect("FantasyGolf.htm");
                //}**/
            }
        }
    
        public string RequestParam(string ParamName, object page)
        {
            // here we can set the theme and the masterpage
            Page p = (Page)page;
    
            string Result = String.Empty;
    
            if (p.Request.Form.Count != 0)
            {
                Result = Convert.ToString(p.Request.Form[ParamName]);
            }
            else if (p.Request.QueryString.Count != 0)
            {
                Result = Convert.ToString(p.Request.QueryString[ParamName]);
            }
    
            return (Result == null) ? String.Empty : Result.Trim();
        }
    
        public static int CountChar(string instance, char c)
        {
            int result = 0;
            foreach (char curChar in instance)
            {
                if (c == curChar)
                {
                    ++result;
                }
            }
            return result;
        }
    
    }


     

     

    Thursday, January 7, 2010 11:41 AM

Answers

  • User-158764254 posted

    I took this as the perfect opportunity to upgrade my developmental tools as well as migrate my web app from .net 2 to .net 3.5.
     

     

    By any chance are you also running against IIS7 now where you might have previously been using IIS5/6?

    There's a different way to register HttpModules and HttpHandlers under IIS7 when running in Integrated Pipeline mode.  refer: http://www.west-wind.com/weblog/posts/168221.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 7, 2010 8:26 PM
  • User758552382 posted

    mb,

     

    That was my problem. I was running in iis5/6 and am running it in 7 on my Win7 dev machine.

     

    However my web.config already contained the line:

    <system.webServer>
    		<validation validateIntegratedModeConfiguration="false"/>
    </system.webServer>


    What I found was that for this to work I needed to include the themeSelector module to the system.webServer module section as well as the system.web section. that allows me to run in both 6 and 7. I have not been able to verify this all still works in 6 though.

    this is what i included in my .config file:

     

    <system.webServer>
       <validation validateIntegratedModeConfiguration="false"/>
       <modules>
                   <add name="ThemeSelector" type="ThemeSelector"/>
       </modules>
    <system.webServer
    

     

    Works in iis7 now.

     

    Ras

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 8, 2010 12:19 PM

All replies

  • User-158764254 posted

    I took this as the perfect opportunity to upgrade my developmental tools as well as migrate my web app from .net 2 to .net 3.5.
     

     

    By any chance are you also running against IIS7 now where you might have previously been using IIS5/6?

    There's a different way to register HttpModules and HttpHandlers under IIS7 when running in Integrated Pipeline mode.  refer: http://www.west-wind.com/weblog/posts/168221.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 7, 2010 8:26 PM
  • User758552382 posted

    mb,

     

    That was my problem. I was running in iis5/6 and am running it in 7 on my Win7 dev machine.

     

    However my web.config already contained the line:

    <system.webServer>
    		<validation validateIntegratedModeConfiguration="false"/>
    </system.webServer>


    What I found was that for this to work I needed to include the themeSelector module to the system.webServer module section as well as the system.web section. that allows me to run in both 6 and 7. I have not been able to verify this all still works in 6 though.

    this is what i included in my .config file:

     

    <system.webServer>
       <validation validateIntegratedModeConfiguration="false"/>
       <modules>
                   <add name="ThemeSelector" type="ThemeSelector"/>
       </modules>
    <system.webServer
    

     

    Works in iis7 now.

     

    Ras

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 8, 2010 12:19 PM
  • User-158764254 posted

    What I found was that for this to work I needed to include the themeSelector module to the system.webServer module section as well as the system.web section. that allows me to run in both 6 and 7
     

    the entries under system.webServer are needed for IIS7 but don't work for iis6

    so you need to also keep your original entries that you had been using for it to work under iis 6.

    iis7 will throw an error if is sees that you've left the IIS6 style module/handler entries in the web.config and thats where the setting validateIntegratedModeConfiguration comes in.  It lets IIS7 know that its ok to ignore the older style entries.

    this is how i set things up as i need to be able to run under either environment depending...

    It's important to remember to update both sections if you are making changes though and still need compatibility with both iis6 and iis7.

    note that if you set your iis7 app pool so that it is not running in Integrated pipeline mode and is instead using the classic mode, then you don't need the settings in that new section as the original module/handler settings would apply.

     

     

     

    Friday, January 8, 2010 12:29 PM