[FIXED] [RC2] Solution for web.config check-out problem in Web Application under source control (Team Foundation Server (TFS))

  1. #1

    [FIXED] [RC2] Solution for web.config check-out problem in Web Application under source control (Team Foundation Server (TFS))

    Dear all,

    There is a problem in v1.0c with web.config file in a Web Application project under Team Foundation Server source control. This file automatically checks out and causes problems for teams of developers.
    --------------------------
    Solution
    I found out that there is a bug in Ext.net source code that tries to open web.config read-write to add missing parts automatically.

    To solve the problem, I changed two parts of the source code to open web.config read-only:

    Therefore, we should use:
     app.OpenWebConfiguration(true);   // opens web.config in read-only mode
    instead of
     app.OpenWebConfiguration(false);  // opens web.config in read-write mode, so causes auto check-out under source control like TFS
    In this case two files should be edited like this: ( I don't know why I can't attach cs files here, so it put the code here.)

    1- Ext.Net\Utility\WebConfigUtils.cs

    	
    
    	// changed by mohghaderi 02 May 2011
            internal static void CheckConfiguration(ISite site)
            {
                if (site == null)
                {
                    return;
                }
    
                IWebApplication app = (IWebApplication)site.GetService(typeof(IWebApplication));
    
                if (app == null)
                {
                    return;
                }
    
                if (!IsChangeRequiredToWebConfig(app))
                {
                    return;
                }
    
    
                Configuration config = app.OpenWebConfiguration(false);
    
                HttpHandlersSection handlers = (HttpHandlersSection)config.GetSection("system.web/httpHandlers");
    
                // Does the httpHandlers Secton already exist?
                if (handlers == null)
                {
                    // If not, add it...
                    handlers = new HttpHandlersSection();
    
                    ConfigurationSectionGroup group = config.GetSectionGroup("system.web");
    
                    // Does the system.web Section already exist?
                    if (group == null)
                    {
                        // If not, add it...
                        config.SectionGroups.Add("system.web", new ConfigurationSectionGroup());
                        group = config.GetSectionGroup("system.web");
                    }
    
                    if (group != null)
                    {
                        group.Sections.Add("httpHandlers", handlers);
                    }
                }
    
                HttpHandlerAction action = new HttpHandlerAction("*/ext.axd", "Ext.Net.ResourceHandler", "*", false);
    
                // Does the ResourceHandler already exist?
                if (handlers.Handlers.IndexOf(action) < 0)
                {
                    // If not, add it...
                    handlers.Handlers.Add(action);
                    config.Save();
                }
    
    
    
                HttpModulesSection modules = (HttpModulesSection)config.GetSection("system.web/httpModules");
    
                // Does the httpModules Secton already exist?
                if (modules == null)
                {
                    // If not, add it...
                    modules = new HttpModulesSection();
    
                    ConfigurationSectionGroup group = config.GetSectionGroup("system.web");
    
                    // Does the system.web Section already exist?
                    if (group == null)
                    {
                        // If not, add it...
                        config.SectionGroups.Add("system.web", new ConfigurationSectionGroup());
                        group = config.GetSectionGroup("system.web");
                    }
    
                    if (group != null)
                    {
                        group.Sections.Add("httpModules", modules);
                    }
                }
    
    
                //<add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net" />
    
                HttpModuleAction action2 = new HttpModuleAction("DirectRequestModule", "Ext.Net.DirectRequestModule, Ext.Net");
    
                // Does the ResourceHandler already exist?
                if (modules.Modules.IndexOf(action2) < 0)
                {
                    // If not, add it...
                    modules.Modules.Add(action2);
                    config.Save();
                }
            }
    
            // added by mohghaderi 02 May 2011
            internal static bool IsChangeRequiredToWebConfig(IWebApplication app)
            {
                Configuration config = app.OpenWebConfiguration(true);
    
                HttpHandlersSection handlers = (HttpHandlersSection)config.GetSection("system.web/httpHandlers");
    
                // Does the httpHandlers Secton already exist?
                if (handlers == null)
                {
                    return true;
                }
    
                HttpHandlerAction action = new HttpHandlerAction("*/ext.axd", "Ext.Net.ResourceHandler", "*", false);
    
                // Does the ResourceHandler already exist?
                if (handlers.Handlers.IndexOf(action) < 0)
                {
                    return true;
                }
    
    
                HttpModulesSection modules = (HttpModulesSection)config.GetSection("system.web/httpModules");
    
                // Does the httpModules Secton already exist?
                if (modules == null)
                {
                    return true;
                }
    
    
                //<add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net" />
    
                HttpModuleAction action2 = new HttpModuleAction("DirectRequestModule", "Ext.Net.DirectRequestModule, Ext.Net");
    
                // Does the ResourceHandler already exist?
                if (modules.Modules.IndexOf(action2) < 0)
                {
                    return true;
                }
    
                return false;
            }


    2- Ext.Net\Core\ResourceHandler.cs

    		
            public static GlobalConfig GetExtNetSection(ISite site)
            {
                if (site != null)
                {
                    IWebApplication app = (IWebApplication)site.GetService(typeof(IWebApplication));
    
                    if (app != null)
                    {
                        Configuration config = app.OpenWebConfiguration(true); // changed by mohghaderi 02 May 2011
    
                        if (config != null)
                        {
                            ConfigurationSection section = config.GetSection("extnet");
    
                            if (section != null)
                            {
                                return section as GlobalConfig;
                            }
                        }
                    }
                }
    
                return null;
            }
    Here is attachments: ResourceHandler.txt WebConfigUtils.txt

    It's nice if you could submit these changes to your newer version of Coolite. Thank you for your time and consideration.

    Best
    Last edited by geoffrey.mcgill; May 31, 2011 at 4:48 PM. Reason: [FIXED]
  2. #2
    Hi mohghaderi,

    Thanks for the great post! I am investigating this right now.
    Geoffrey McGill
    Founder
  3. #3
    Hi,

    This has been fixed.

    The call to Ext.Net\Core\ResourceHandler.cs .CheckConfiguration() was removed. This code is no longer called.

    In Ext.Net\Utility\WebConfigUtils.cs, .GetExtNetSection() 'true' is now being passed to ensure web.config is opened in Read-only mode.

    Thanks again for pointing out the problems.
    Geoffrey McGill
    Founder

Similar Threads

  1. RTL Problem & Solution
    By Paula in forum Examples and Extras
    Replies: 8
    Last Post: May 17, 2012, 12:33 PM
  2. [CLOSED] Client and Server side form validation best solution
    By FAS in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Feb 09, 2012, 4:33 PM
  3. Replies: 2
    Last Post: Oct 24, 2011, 3:43 PM
  4. [FIXED] [1.2] Sys.Application is undefined
    By Leonid_Veriga in forum Bugs
    Replies: 6
    Last Post: Oct 21, 2011, 10:51 AM
  5. [CLOSED] Server Error in '/' Application.
    By Vasudhaika in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Aug 19, 2010, 4:38 AM

Posting Permissions