Beispiel #1
0
        public UsingHttpModulesSection()
        {
            // <Snippet1>

// Get the Web application configuration.
            Configuration configuration = WebConfigurationManager.OpenWebConfiguration("/aspnetTest");

// Get the HttpModulesSection.
            HttpModulesSection httpModulesSection = (HttpModulesSection)configuration.GetSection("system.web/httpModules");

// </Snippet1>

// <Snippet2>

// Create a new HttpModulesSection object.
            HttpModulesSection newHttpModulesSection = new HttpModulesSection();

// </Snippet2>

// <Snippet3>

// Get the modules collection.
            HttpModuleActionCollection httpModules = httpModulesSection.Modules;

// Read the modules information.
            StringBuilder modulesInfo = new StringBuilder();

            for (int i = 0; i < httpModules.Count; i++)
            {
                modulesInfo.Append(
                    string.Format("Name: {0}\nType: {1}\n\n", httpModules[i].Name,
                                  httpModules[i].Type));
            }
// </Snippet3>
        }
Beispiel #2
0
        private static void ValidateTheWebApplicationInitialiserModuleIsIncluded(HttpApplication app)
        {
            object webServerSection = ConfigurationManager.GetSection("system.webServer");
            var    sect             = webServerSection as IgnoreSection;

            sect.SectionInformation.GetRawXml();
            bool hasModule = false;

            //if not iis 7 integrated mode
            HttpModulesSection httpModulesSection =
                ConfigurationManager.GetSection("system.web/httpModules") as HttpModulesSection;

            foreach (HttpModuleAction module in httpModulesSection.Modules)
            {
                if (module.Type.Contains(typeof(WebApplicationInitialiserModule).Name))
                {
                    hasModule = true;
                }
            }
            // if iis 6 or iis 7 classic mode


            // throw exception if the module hasn't been found
            if (hasModule == false)
            {
                throw new Exception("The webinitialiser requires the WebApplicationInitialisationModule to be added to the web.config to operate correctly. Please add the module before any other modules");
            }
        }
        public static bool CheckUrlAccessForPrincipal(string virtualPath, IPrincipal user, string verb)
        {
            if (virtualPath == null)
            {
                throw new ArgumentNullException("virtualPath");
            }
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (verb == null)
            {
                throw new ArgumentNullException("verb");
            }
            verb = verb.Trim();
            VirtualPath path = VirtualPath.Create(virtualPath);

            if (!path.IsWithinAppRoot)
            {
                throw new ArgumentException(System.Web.SR.GetString("Virtual_path_outside_application_not_supported"), "virtualPath");
            }
            if (!s_EnabledDetermined)
            {
                if (!HttpRuntime.UseIntegratedPipeline)
                {
                    HttpModulesSection httpModules = RuntimeConfig.GetConfig().HttpModules;
                    int count = httpModules.Modules.Count;
                    for (int i = 0; i < count; i++)
                    {
                        HttpModuleAction action = httpModules.Modules[i];
                        if (Type.GetType(action.Type, false) == typeof(UrlAuthorizationModule))
                        {
                            s_Enabled = true;
                            break;
                        }
                    }
                }
                else
                {
                    foreach (ModuleConfigurationInfo info in HttpApplication.IntegratedModuleList)
                    {
                        if (Type.GetType(info.Type, false) == typeof(UrlAuthorizationModule))
                        {
                            s_Enabled = true;
                            break;
                        }
                    }
                }
                s_EnabledDetermined = true;
            }
            if (s_Enabled)
            {
                AuthorizationSection authorization = RuntimeConfig.GetConfig(path).Authorization;
                if (!authorization.EveryoneAllowed)
                {
                    return(authorization.IsUserAllowed(user, verb));
                }
            }
            return(true);
        }
Beispiel #4
0
        // https://msdn.microsoft.com/en-us/library/tkwek5a4%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
        // Example Configuration Code for an HTTP Module:

        public static void AddModule(Configuration config, string moduleName, string moduleClass)
        {
            HttpModulesSection section =
                (HttpModulesSection)config.GetSection("system.web/httpModules");

            // Create a new module action object.
            HttpModuleAction moduleAction = new HttpModuleAction(
                moduleName, moduleClass);
            // "RequestTimeIntervalModule", "Samples.Aspnet.HttpModuleExamples.RequestTimeIntervalModule");

            // Look for an existing configuration for this module.
            int indexOfModule = section.Modules.IndexOf(moduleAction);

            if (-1 != indexOfModule)
            {
                // Console.WriteLine("RequestTimeIntervalModule module is already configured at index {0}", indexOfModule);
            }
            else
            {
                section.Modules.Add(moduleAction);

                if (!section.SectionInformation.IsLocked)
                {
                    config.Save();
                    // Console.WriteLine("RequestTimeIntervalModule module configured.");
                }
            }
        }
        /// <summary>
        /// 获取HttpModulesSection
        /// </summary>
        /// <returns></returns>
        public static HttpModulesSection GetHttpModulesSection()
        {
            HttpModulesSection section = (HttpModulesSection)ConfigurationBroker.GetSection("deluxe.web/httpModules");

            if (section == null)
            {
                section = new HttpModulesSection();
            }

            return(section);
        }
Beispiel #6
0
        static int integralFlag = -1;//集成模式
        void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;

            context = app.Context;
            if (context.Request.Url.LocalPath == "/")//设置默认首页
            {
                string defaultUrl = WebHelper.GetDefaultUrl();
                if (!string.IsNullOrEmpty(defaultUrl))
                {
                    context.RewritePath(defaultUrl, false);
                }
            }
            else
            {
                //VS2013(以上)IISExpress 默认会检测文件存在,导致后续事件无法触发,因此需要做点小事情做兼容)
                //正常IIS部署,是不需要以前兼容性代码的,(该代码将路径重写到一个已存在的文件,同时在目录下新建了一个ajax.html文件)
                //简单的地说:以上这段代码,和根目录下的ajax.html文件,是为了兼容VS IISExpress的bug存在的(微软造的孽)。
#if DEBUG
                if (integralFlag == -1)
                {
                    integralFlag = 1;
                    HttpModulesSection ab = (HttpModulesSection)ConfigurationManager.GetSection("system.web/httpModules");
                    if (ab != null)
                    {
                        foreach (HttpModuleAction item in ab.Modules)
                        {
                            if (item.Name == "Aries.Core")
                            {
                                integralFlag = 0; break;
                            }
                        }
                    }
                }
                //VS2012 或以下,可以注释掉以下这段代码。
                //string iisName=context.Request.ServerVariables["SERVER_SOFTWARE"];
                //if (!string.IsNullOrEmpty(iisName) && iisName.StartsWith("Microsoft-IIS/1"))
                //{
                //VS2015和VS 2017 Microsoft-IIS/10.0
                if (integralFlag == 1 && WebHelper.IsAriesSuffix())
                {
                    string uriPath = Path.GetFileNameWithoutExtension(context.Request.Url.LocalPath).ToLower();
                    isAjax = uriPath == "ajax";
                    if (isAjax)
                    {
                        string localPath = context.Request.Url.PathAndQuery;
                        int    i         = localPath.LastIndexOf('/');
                        context.RewritePath(localPath.Substring(i), true);//只有重定向到一个存在的文件,兼容微软造的孽
                    }
                }
                // }
#endif
            }
        }
Beispiel #7
0
        public ActionResult HttpModules()
        {
            HttpModulesSection section = GetConfigSetting <HttpModulesSection>("HttpModules");

            var httpModules =
                from h in section.Modules.Cast <HttpModuleAction>()
                let action =
                    $"path=\"{h.Name}\" type=\"{h.Type}\""
                    select action;

            return(View("HttpView", httpModules));
        }
Beispiel #8
0
        private static void AddWebModules(System.Configuration.Configuration config, string name, string type)
        {
            // Get the <httpModules> section.
            HttpModulesSection sectionSystemWeb = (HttpModulesSection)config.GetSection("system.web/httpModules");

            // Create a new module action object.
            HttpModuleAction myHttpModuleAction = new HttpModuleAction(name, type);

            int indexOfHttpModule = sectionSystemWeb.Modules.IndexOf(myHttpModuleAction);

            if (indexOfHttpModule == -1)
            {
                sectionSystemWeb.Modules.Add(myHttpModuleAction);
                if (!sectionSystemWeb.SectionInformation.IsLocked)
                {
                    config.Save();
                }
            }
        }
        /// <summary>
        /// Check if TenorModule is defined on configuration file.
        /// </summary>
        /// <returns>True if the module is defined.
        /// </returns>
        private static bool CheckHttpModules()
        {
            HttpModulesSection sec = (HttpModulesSection)(WebConfigurationManager.GetSection("system.web/httpModules"));

            if (sec == null)
            {
                return(false);
            }

            foreach (HttpModuleAction m in sec.Modules)
            {
                if (m.Type.StartsWith("Tenor.Web.TenorModule, Tenor"))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #10
0
        /// <summary>
        /// Check if TenorModule is enabled on user-code webconfig.
        /// </summary>
        private static bool CheckHttpModules()
        {
            Type httpModule        = typeof(TenorModule);
            HttpModulesSection sec = (HttpModulesSection)(WebConfigurationManager.GetSection("system.web/httpModules"));

            if (sec == null)
            {
                return(false);
            }

            foreach (HttpModuleAction m in sec.Modules)
            {
                if (m.Type.StartsWith(string.Format("{0}, {1}", httpModule.FullName, httpModule.Assembly.GetName().Name)))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #11
0
        private IEnumerable <ConfigurationHttpModulesModel> ProcessHttpModules(HttpModulesSection httpModulesSection)
        {
            if (httpModulesSection == null)
            {
                return(null);
            }

            var result = new List <ConfigurationHttpModulesModel>();

            foreach (HttpModuleAction httpModule in httpModulesSection.Modules)
            {
                var resultItem = new ConfigurationHttpModulesModel {
                    Name = httpModule.Name, Type = httpModule.Type
                };

                result.Add(resultItem);
            }

            return(result);
        }
Beispiel #12
0
            private static void AddModuleToClassicPipeline(Type moduleType)
            {
                HttpModulesSection httpModulesFromAppConfig = null;

                try
                {
                    object target = _reflectionUtil.GetAppConfig();
                    httpModulesFromAppConfig = _reflectionUtil.GetHttpModulesFromAppConfig(target);
                    _reflectionUtil.SetConfigurationElementCollectionReadOnlyBit(httpModulesFromAppConfig.Modules, false);
                    CHystrix.Utils.CFX.DynamicModuleRegistryEntry entry = CreateDynamicModuleRegistryEntry(moduleType);
                    httpModulesFromAppConfig.Modules.Add(new HttpModuleAction(entry.Name, entry.Type));
                }
                finally
                {
                    if (httpModulesFromAppConfig != null)
                    {
                        _reflectionUtil.SetConfigurationElementCollectionReadOnlyBit(httpModulesFromAppConfig.Modules, true);
                    }
                }
            }
Beispiel #13
0
        /// <summary>
        /// Init HttpModule
        /// </summary>
        /// <param name="context"></param>
        protected virtual void Init(HttpApplication context)
        {
            _HttpModuleCollection = new Dictionary <string, IHttpModule>();

            HttpModulesSection moduleSection = ConfigSectionFactory.GetHttpModulesSection();

            foreach (HttpModuleAction moduleAction in moduleSection.Modules)
            {
                try
                {
                    IHttpModule module = (IHttpModule)TypeCreator.CreateInstance(moduleAction.Type);

                    this._HttpModuleCollection.Add(moduleAction.Name, module);

                    module.Init(context);
                }
                catch (TypeLoadException ex)
                {
                    ex.TryWriteAppLog();
                }
            }
        }
Beispiel #14
0
        public static void EnumerateHttpModules(string url, HttpResponse response)
        {
            Configuration config = WebConfigurationManager.OpenWebConfiguration(url);

            // Get the <httpModules> section.
            HttpModulesSection section =
                (HttpModulesSection)config.GetSection("system.web/httpModules");

            StringBuilder output = new StringBuilder();

            output.AppendFormat("<div><httpModules> modules element in {0}:<br/>",
                                config.FilePath.ToString());

            for (int i = 0; i < section.Modules.Count; i++)
            {
                output.AppendFormat("<span>{0}, {1}</span><br/>",
                                    section.Modules[i].Name.ToString(),
                                    section.Modules[i].Type.ToString());
            }

            output.AppendFormat("</div>");

            response.Write(output);
        }
        public static bool CheckFileAccessForUser(string virtualPath, IntPtr token, string verb)
        {
            bool flag;

            if (virtualPath == null)
            {
                throw new ArgumentNullException("virtualPath");
            }
            if (token == IntPtr.Zero)
            {
                throw new ArgumentNullException("token");
            }
            if (verb == null)
            {
                throw new ArgumentNullException("verb");
            }
            VirtualPath path = VirtualPath.Create(virtualPath);

            if (!path.IsWithinAppRoot)
            {
                throw new ArgumentException(System.Web.SR.GetString("Virtual_path_outside_application_not_supported"), "virtualPath");
            }
            if (!s_EnabledDetermined)
            {
                if (HttpRuntime.UseIntegratedPipeline)
                {
                    s_Enabled = true;
                }
                else
                {
                    HttpModulesSection httpModules = RuntimeConfig.GetConfig().HttpModules;
                    int count = httpModules.Modules.Count;
                    for (int i = 0; i < count; i++)
                    {
                        HttpModuleAction action = httpModules.Modules[i];
                        if (Type.GetType(action.Type, false) == typeof(FileAuthorizationModule))
                        {
                            s_Enabled = true;
                            break;
                        }
                    }
                }
                s_EnabledDetermined = true;
            }
            if (!s_Enabled)
            {
                return(true);
            }
            FileSecurityDescriptorWrapper fileSecurityDescriptorWrapper = GetFileSecurityDescriptorWrapper(path.MapPath(), out flag);
            int iAccess = 3;

            if (((verb == "GET") || (verb == "POST")) || ((verb == "HEAD") || (verb == "OPTIONS")))
            {
                iAccess = 1;
            }
            bool flag2 = fileSecurityDescriptorWrapper.IsAccessAllowed(token, iAccess);

            if (flag)
            {
                fileSecurityDescriptorWrapper.FreeSecurityDescriptor();
            }
            return(flag2);
        }
Beispiel #16
0
        public static void Main()
        {
            // <Snippet1>

            // Get the Web application configuration.
            System.Configuration.Configuration configuration =
                WebConfigurationManager.OpenWebConfiguration("/aspnetTest");

            // Get the section.
            HttpModulesSection httpModulesSection =
                (HttpModulesSection)configuration.GetSection(
                    "system.web/httpModules");

            // </Snippet1>


            // <Snippet2>
            // Create a new section object.
            HttpModuleAction newModuleAction =
                new HttpModuleAction("MyModule",
                                     "MyModuleType");

            // </Snippet2>


            // <Snippet3>

            // Initialize the module name and type properties.
            newModuleAction.Name = "ModuleName";
            newModuleAction.Type = "ModuleType";

            // </Snippet3>

            // <Snippet4>

            // Get the modules collection.
            HttpModuleActionCollection httpModules =
                httpModulesSection.Modules;
            string moduleFound = "moduleName not found.";

            // Find the module with the specified name.
            foreach (HttpModuleAction currentModule in httpModules)
            {
                if (currentModule.Name == "moduleName")
                {
                    moduleFound = "moduleName found.";
                }
            }
            // </Snippet4>



            // <Snippet5>

            // Get the modules collection.
            HttpModuleActionCollection httpModules2 =
                httpModulesSection.Modules;
            string typeFound = "typeName not found.";

            // Find the module with the specified type.
            foreach (HttpModuleAction currentModule in httpModules2)
            {
                if (currentModule.Type == "typeName")
                {
                    typeFound = "typeName found.";
                }
            }

            // </Snippet5>
        }
Beispiel #17
0
        internal static void CheckConfiguration(ISite site)
        {
            if (site == null)
            {
                return;
            }

            IWebApplication app = (IWebApplication)site.GetService(typeof(IWebApplication));

            if (app == null)
            {
                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();
            }
        }
Beispiel #18
0
        public static bool CheckFileAccessForUser(String virtualPath, IntPtr token, string verb)
        {
            if (virtualPath == null)
            {
                throw new ArgumentNullException("virtualPath");
            }
            if (token == IntPtr.Zero)
            {
                throw new ArgumentNullException("token");
            }
            if (verb == null)
            {
                throw new ArgumentNullException("verb");
            }
            VirtualPath vPath = VirtualPath.Create(virtualPath);

            if (!vPath.IsWithinAppRoot)
            {
                throw new ArgumentException(SR.GetString(SR.Virtual_path_outside_application_not_supported), "virtualPath");
            }

            if (!s_EnabledDetermined)
            {
                if (HttpRuntime.UseIntegratedPipeline)
                {
                    s_Enabled = true; // always enabled in Integrated Mode
                }
                else
                {
                    HttpModulesSection modulesSection = RuntimeConfig.GetConfig().HttpModules;
                    int len = modulesSection.Modules.Count;
                    for (int iter = 0; iter < len; iter++)
                    {
                        HttpModuleAction module = modulesSection.Modules[iter];
                        if (Type.GetType(module.Type, false) == typeof(FileAuthorizationModule))
                        {
                            s_Enabled = true;
                            break;
                        }
                    }
                }
                s_EnabledDetermined = true;
            }
            if (!s_Enabled)
            {
                return(true);
            }
            ////////////////////////////////////////////////////////////
            // Step 3: Check the cache for the file-security-descriptor
            //        for the requested file
            bool freeDescriptor;
            FileSecurityDescriptorWrapper oSecDesc = GetFileSecurityDescriptorWrapper(vPath.MapPath(), out freeDescriptor);

            ////////////////////////////////////////////////////////////
            // Step 4: Check if access is allowed
            int iAccess = 3;

            if (verb == "GET" || verb == "POST" || verb == "HEAD" || verb == "OPTIONS")
            {
                iAccess = 1;
            }
            bool fAllowed = oSecDesc.IsAccessAllowed(token, iAccess);

            ////////////////////////////////////////////////////////////
            // Step 5: Free the security descriptor if adding to cache failed
            if (freeDescriptor)
            {
                oSecDesc.FreeSecurityDescriptor();
            }
            return(fAllowed);
        }
        static void Main(string[] args)
        {
            string inputStr = String.Empty;
            string option   = String.Empty;

            // Define a regular expression to allow only
            // alphanumeric inputs that are at most 20 character
            // long. For instance "/iii:".
            Regex rex = new Regex(@"[^\/w]{1,20}:");

            // Parse the user's input.
            if (args.Length < 1)
            {
                // No option entered.
                Console.Write("Input parameter missing.");
                return;
            }
            else
            {
                // Get the user's option.
                inputStr = args[0].ToLower();
                if (!(rex.Match(inputStr)).Success)
                {
                    // Wrong option format used.
                    Console.Write("Input parameter format not allowed.");
                    return;
                }
            }

            // <Snippet1>

            // Get the Web application configuration.
            System.Configuration.Configuration configuration =
                WebConfigurationManager.OpenWebConfiguration(
                    "/aspnetTest");

            // Get the <system.web> group.
            SystemWebSectionGroup systemWeb =
                (SystemWebSectionGroup)configuration.GetSectionGroup("system.web");

            // </Snippet1>


            try
            {
                switch (inputStr)
                {
                case "/anonymous:":
                    // <Snippet2>
                    // Get the anonymousIdentification section.
                    AnonymousIdentificationSection
                        anonymousIdentification =
                        systemWeb.AnonymousIdentification;
                    // Read section information.
                    info =
                        anonymousIdentification.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet2>

                    Console.Write(msg);
                    break;

                case "/authentication:":

                    // <Snippet3>
                    // Get the authentication section.
                    AuthenticationSection authentication =
                        systemWeb.Authentication;
                    // Read section information.
                    info =
                        authentication.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet3>

                    Console.Write(msg);
                    break;

                case "/authorization:":

                    // <Snippet4>
                    // Get the authorization section.
                    AuthorizationSection authorization =
                        systemWeb.Authorization;
                    // Read section information.
                    info =
                        authorization.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet4>

                    Console.Write(msg);
                    break;

                case "/compilation:":

                    // <Snippet5>
                    // Get the compilation section.
                    CompilationSection compilation =
                        systemWeb.Compilation;
                    // Read section information.
                    info =
                        compilation.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet5>

                    Console.Write(msg);
                    break;


                case "/customerrors:":

                    // <Snippet6>
                    // Get the customerrors section.
                    CustomErrorsSection customerrors =
                        systemWeb.CustomErrors;
                    // Read section information.
                    info =
                        customerrors.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet6>

                    Console.Write(msg);
                    break;

                case "/globalization:":

                    // <Snippet7>
                    // Get the globalization section.
                    GlobalizationSection globalization =
                        systemWeb.Globalization;
                    // Read section information.
                    info =
                        globalization.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet7>

                    Console.Write(msg);
                    break;

                case "/httpcookies:":
                    // <Snippet8>
                    // Get the httpCookies section.
                    HttpCookiesSection httpCookies =
                        systemWeb.HttpCookies;
                    // Read section information.
                    info =
                        httpCookies.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet8>

                    Console.Write(msg);
                    break;

                case "/httphandlers:":

                    // <Snippet9>
                    // Get the httpHandlers section.
                    HttpHandlersSection httpHandlers =
                        systemWeb.HttpHandlers;
                    // Read section information.
                    info =
                        httpHandlers.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet9>

                    Console.Write(msg);
                    break;

                case "/httpmodules:":

                    // <Snippet10>
                    // Get the httpModules section.
                    HttpModulesSection httpModules =
                        systemWeb.HttpModules;
                    // Read section information.
                    info =
                        httpModules.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet10>

                    Console.Write(msg);
                    break;

                case "/httpruntime:":

                    // <Snippet11>
                    // Get the httpRuntime section.
                    HttpRuntimeSection httpRuntime =
                        systemWeb.HttpRuntime;
                    // Read section information.
                    info =
                        httpRuntime.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet11>

                    Console.Write(msg);
                    break;

                case "/identity:":

                    // <Snippet12>
                    // Get the identity section.
                    IdentitySection identity =
                        systemWeb.Identity;
                    // Read section information.
                    info =
                        identity.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet12>

                    Console.Write(msg);
                    break;

                case "/machinekey:":

                    // <Snippet13>
                    // Get the machineKey section.
                    MachineKeySection machineKey =
                        systemWeb.MachineKey;
                    // Read section information.
                    info =
                        machineKey.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet13>

                    Console.Write(msg);
                    break;

                case "/membership:":
                    // <Snippet14>
                    // Get the membership section.
                    MembershipSection membership =
                        systemWeb.Membership;
                    // Read section information.
                    info =
                        membership.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet14>

                    Console.Write(msg);
                    break;

                case "/pages:":
                    // <Snippet15>
                    // Get the pages section.
                    PagesSection pages =
                        systemWeb.Pages;
                    // Read section information.
                    info =
                        pages.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet15>

                    Console.Write(msg);
                    break;

                case "/processModel:":
                    // <Snippet16>
                    // Get the processModel section.
                    ProcessModelSection processModel =
                        systemWeb.ProcessModel;
                    // Read section information.
                    info =
                        processModel.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet16>

                    Console.Write(msg);
                    break;

                case "/profile:":
                    // <Snippet17>
                    // Get the profile section.
                    ProfileSection profile =
                        systemWeb.Profile;
                    // Read section information.
                    info =
                        profile.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet17>

                    Console.Write(msg);
                    break;

                case "/roleManager:":
                    // <Snippet18>
                    // Get the roleManager section.
                    RoleManagerSection roleManager =
                        systemWeb.RoleManager;
                    // Read section information.
                    info =
                        roleManager.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet18>

                    Console.Write(msg);
                    break;

                case "/securityPolicy:":
                    // <Snippet19>
                    // Get the securityPolicy section.
                    SecurityPolicySection securityPolicy =
                        systemWeb.SecurityPolicy;
                    // Read section information.
                    info =
                        securityPolicy.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet19>

                    Console.Write(msg);
                    break;

                case "/sessionState:":
                    // <Snippet20>
                    // Get the sessionState section.
                    SessionStateSection sessionState =
                        systemWeb.SessionState;
                    // Read section information.
                    info =
                        sessionState.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet20>

                    Console.Write(msg);
                    break;

                case "/sitemap:":
                    // <Snippet21>
                    // Get the siteMap section.
                    SiteMapSection siteMap =
                        systemWeb.SiteMap;
                    // Read section information.
                    info =
                        siteMap.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet21>

                    Console.Write(msg);
                    break;

                case "/trace:":
                    // <Snippet22>
                    // Get the trace section.
                    TraceSection trace =
                        systemWeb.Trace;
                    // Read section information.
                    info =
                        trace.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet22>

                    Console.Write(msg);
                    break;

                case "/trust:":
                    // <Snippet23>
                    // Get the trust section.
                    TrustSection trust =
                        systemWeb.Trust;
                    // Read section information.
                    info =
                        trust.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet23>

                    Console.Write(msg);
                    break;

                case "/browserCaps:":
                    // <Snippet24>
                    // Get the browserCaps section.
                    DefaultSection browserCaps =
                        systemWeb.BrowserCaps;
                    // Read section information.
                    info =
                        browserCaps.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet24>

                    Console.Write(msg);
                    break;

                case "/clientTarget:":
                    // <Snippet25>
                    // Get the clientTarget section.
                    ClientTargetSection clientTarget =
                        systemWeb.ClientTarget;
                    // Read section information.
                    info =
                        clientTarget.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet25>

                    Console.Write(msg);
                    break;


                case "/deployment:":
                    // <Snippet26>
                    // Get the deployment section.
                    DeploymentSection deployment =
                        systemWeb.Deployment;
                    // Read section information.
                    info =
                        deployment.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet26>

                    Console.Write(msg);
                    break;


                case "/deviceFilters:":
                    // <Snippet27>
                    // Get the deviceFilters section.
                    DefaultSection deviceFilters =
                        systemWeb.DeviceFilters;
                    // Read section information.
                    info =
                        deviceFilters.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet27>

                    Console.Write(msg);
                    break;

                case "/healthMonitoring:":
                    // <Snippet28>
                    // Get the healthMonitoring section.
                    HealthMonitoringSection healthMonitoring =
                        systemWeb.HealthMonitoring;
                    // Read section information.
                    info =
                        healthMonitoring.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet28>

                    Console.Write(msg);
                    break;

                case "/hostingEnvironment:":
                    // <Snippet29>
                    // Get the hostingEnvironment section.
                    HostingEnvironmentSection hostingEnvironment =
                        systemWeb.HostingEnvironment;
                    // Read section information.
                    info =
                        hostingEnvironment.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet29>

                    Console.Write(msg);
                    break;

                case "/mobileControls:":
                    // <Snippet30>
                    // Get the mobileControls section.
                    ConfigurationSection mobileControls =
                        systemWeb.MobileControls;
                    // Read section information.
                    info =
                        mobileControls.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet30>

                    Console.Write(msg);
                    break;

                case "/protocols:":
                    // <Snippet31>
                    // Get the protocols section.
                    DefaultSection protocols =
                        systemWeb.Protocols;
                    // Read section information.
                    info =
                        protocols.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet31>

                    Console.Write(msg);
                    break;

                case "/urlMappings:":
                    // <Snippet32>
                    // Get the urlMappings section.
                    UrlMappingsSection urlMappings =
                        systemWeb.UrlMappings;
                    // Read section information.
                    info =
                        urlMappings.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet32>

                    Console.Write(msg);
                    break;

                case "/webControls:":
                    // <Snippet33>
                    // Get the webControls section.
                    WebControlsSection webControls =
                        systemWeb.WebControls;
                    // Read section information.
                    info =
                        webControls.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet33>

                    Console.Write(msg);
                    break;

                case "/webParts:":
                    // <Snippet34>
                    // Get the webParts section.
                    WebPartsSection webParts =
                        systemWeb.WebParts;
                    // Read section information.
                    info =
                        webParts.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet34>

                    Console.Write(msg);
                    break;

                case "/webServices:":
                    // <Snippet35>
                    // Get the webServices section.
                    WebServicesSection webServices =
                        systemWeb.WebServices;
                    // Read section information.
                    info =
                        webServices.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet35>

                    Console.Write(msg);
                    break;

                case "/XhtmlConformance:":
                    // <Snippet36>
                    // Get the xhtmlConformance section.
                    XhtmlConformanceSection xhtmlConformance =
                        systemWeb.XhtmlConformance;
                    // Read section information.
                    info =
                        xhtmlConformance.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();

                    msg = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet36>

                    Console.Write(msg);
                    break;


                case "/all:":
                    StringBuilder             allSections    = new StringBuilder();
                    ConfigurationSectionGroup systemWebGroup =
                        configuration.GetSectionGroup("system.web");
                    int i = 0;
                    foreach (ConfigurationSection section in
                             systemWebGroup.Sections)
                    {
                        i       += 1;
                        info     = section.SectionInformation;
                        name     = info.SectionName;
                        type     = info.Type;
                        declared = info.IsDeclared.ToString();
                        if (i < 10)
                        {
                            msg = String.Format(
                                "{0})Name:   {1}\nDeclared: {2}\nType:     {3}\n",
                                i.ToString(), name, declared, type);
                        }
                        else
                        {
                            msg = String.Format(
                                "{0})Name:  {1}\nDeclared: {2}\nType:     {3}\n",
                                i.ToString(), name, declared, type);
                        }
                        allSections.AppendLine(msg);
                    }

                    // Console.WriteLine(systemWebGroup.Name);
                    // Console.WriteLine(systemWebGroup.SectionGroupName);

                    Console.Write(allSections.ToString());
                    break;

                default:
                    // Option is not allowed..
                    Console.Write("Input not allowed.");
                    break;
                }
            }
            catch (ArgumentException e)
            {
                // Never display this. Use it for
                // debugging purposes.
                msg = e.ToString();
            }
        }
Beispiel #20
0
        public static bool CheckUrlAccessForPrincipal(String virtualPath, IPrincipal user, string verb)
        {
            if (virtualPath == null)
            {
                throw new ArgumentNullException("virtualPath");
            }
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (verb == null)
            {
                throw new ArgumentNullException("verb");
            }
            verb = verb.Trim();

            VirtualPath vPath = VirtualPath.Create(virtualPath);

            if (!vPath.IsWithinAppRoot)
            {
                throw new ArgumentException(SR.GetString(SR.Virtual_path_outside_application_not_supported), "virtualPath");
            }

            if (!s_EnabledDetermined)
            {
                if (!HttpRuntime.UseIntegratedPipeline)
                {
                    HttpModulesSection modulesSection = RuntimeConfig.GetConfig().HttpModules;
                    int len = modulesSection.Modules.Count;
                    for (int iter = 0; iter < len; iter++)
                    {
                        HttpModuleAction module = modulesSection.Modules[iter];
                        if (Type.GetType(module.Type, false) == typeof(UrlAuthorizationModule))
                        {
                            s_Enabled = true;
                            break;
                        }
                    }
                }
                else
                {
                    List <ModuleConfigurationInfo> modules = HttpApplication.IntegratedModuleList;
                    foreach (ModuleConfigurationInfo mod in modules)
                    {
                        if (Type.GetType(mod.Type, false) == typeof(UrlAuthorizationModule))
                        {
                            s_Enabled = true;
                            break;
                        }
                    }
                }
                s_EnabledDetermined = true;
            }
            if (!s_Enabled)
            {
                return(true);
            }
            AuthorizationSection settings = RuntimeConfig.GetConfig(vPath).Authorization;

            // Check if the user is allowed, or the request is for the login page
            return(settings.EveryoneAllowed || settings.IsUserAllowed(user, verb));
        }
Beispiel #21
0
        public void RunDeploy(String[] args)
        {
            if (args.Length < 3)
            {
                Console.Error.WriteLine("rdfWebDeploy: Error: 3 Arguments are required in order to use the -deploy mode, type rdfWebDeploy -help to see usage summary");
                return;
            }
            if (args.Length > 3)
            {
                if (!this.SetOptions(args.Skip(3).ToArray()))
                {
                    Console.Error.WriteLine("rdfWebDeploy: Deployment aborted since one/more options were not valid");
                    return;
                }
            }

            if (this._noLocalIIS)
            {
                Console.WriteLine("rdfWebDeploy: No Local IIS Server available so switching to -xmldeploy mode");
                XmlDeploy xdeploy = new XmlDeploy();
                xdeploy.RunXmlDeploy(args);
                return;
            }

            //Define the Server Manager object
            Admin.ServerManager manager = null;

            try
            {
                //Connect to the Server Manager
                if (!this._noIntegratedRegistration)
                {
                    manager = new Admin.ServerManager();
                }

                //Open the Configuration File
                System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(args[1], this._site);
                Console.Out.WriteLine("rdfWebDeploy: Opened the Web.config file for the specified Web Application");

                //Detect Folders
                String appFolder     = Path.GetDirectoryName(config.FilePath);
                String binFolder     = Path.Combine(appFolder, "bin\\");
                String appDataFolder = Path.Combine(appFolder, "App_Data\\");
                if (!Directory.Exists(binFolder))
                {
                    Directory.CreateDirectory(binFolder);
                    Console.WriteLine("rdfWebDeploy: Created a bin\\ directory for the web application");
                }
                if (!Directory.Exists(appDataFolder))
                {
                    Directory.CreateDirectory(appDataFolder);
                    Console.WriteLine("rdfWebDeploy: Created an App_Data\\ directory for the web application");
                }

                //Deploy dotNetRDF and required DLLs to the bin directory of the application
                String sourceFolder       = RdfWebDeployHelper.ExecutablePath;
                IEnumerable <String> dlls = RdfWebDeployHelper.RequiredDLLs;
                if (this._sql)
                {
                    dlls = dlls.Concat(RdfWebDeployHelper.RequiredSqlDLLs);
                }
                if (this._virtuoso)
                {
                    dlls = dlls.Concat(RdfWebDeployHelper.RequiredVirtuosoDLLs);
                }
                if (this._fulltext)
                {
                    dlls = dlls.Concat(RdfWebDeployHelper.RequiredFullTextDLLs);
                }
                foreach (String dll in dlls)
                {
                    if (File.Exists(Path.Combine(sourceFolder, dll)))
                    {
                        File.Copy(Path.Combine(sourceFolder, dll), Path.Combine(binFolder, dll), true);
                        Console.WriteLine("rdfWebDeploy: Deployed " + dll + " to the web applications bin directory");
                    }
                    else
                    {
                        Console.Error.WriteLine("rdfWebDeploy: Error: Required DLL " + dll + " which needs deploying to the web applications bin directory could not be found");
                        return;
                    }
                }

                //Deploy the configuration file to the App_Data directory
                if (File.Exists(args[2]))
                {
                    File.Copy(args[2], Path.Combine(appDataFolder, args[2]), true);
                    Console.WriteLine("rdfWebDeploy: Deployed the configuration file to the web applications App_Data directory");
                }
                else if (!File.Exists(Path.Combine(appDataFolder, args[2])))
                {
                    Console.Error.WriteLine("rdfWebDeploy: Error: Unable to continue deployment as the configuration file " + args[2] + " could not be found either locally for deployment to the App_Data folder or already present in the App_Data folder");
                    return;
                }

                //Set the AppSetting for the configuration file
                config.AppSettings.Settings.Remove("dotNetRDFConfig");
                config.AppSettings.Settings.Add("dotNetRDFConfig", "~/App_Data/" + Path.GetFileName(args[2]));
                Console.WriteLine("rdfWebDeploy: Set the \"dotNetRDFConfig\" appSetting to \"~/App_Data/" + Path.GetFileName(args[2]) + "\"");

                //Now load the Configuration Graph from the App_Data folder
                Graph g = new Graph();
                FileLoader.Load(g, Path.Combine(appDataFolder, args[2]));

                Console.WriteLine("rdfWebDeploy: Successfully deployed required DLLs and appSettings");
                Console.WriteLine();

                //Get the sections of the Configuration File we want to edit
                HttpHandlersSection handlersSection = config.GetSection("system.web/httpHandlers") as HttpHandlersSection;
                if (handlersSection == null)
                {
                    Console.Error.WriteLine("rdfWebDeploy: Error: Unable to access the Handlers section of the web applications Web.Config file");
                    return;
                }

                //Detect Handlers from the Configution Graph and deploy
                IUriNode rdfType     = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType));
                IUriNode dnrType     = g.CreateUriNode(new Uri(ConfigurationLoader.PropertyType));
                IUriNode httpHandler = g.CreateUriNode(new Uri(ConfigurationLoader.ClassHttpHandler));

                //Deploy for IIS Classic Mode
                if (!this._noClassicRegistration)
                {
                    Console.WriteLine("rdfWebDeploy: Attempting deployment for IIS Classic Mode");
                    foreach (INode n in g.GetTriplesWithPredicateObject(rdfType, httpHandler).Select(t => t.Subject))
                    {
                        if (n.NodeType == NodeType.Uri)
                        {
                            String handlerPath = ((IUriNode)n).Uri.AbsolutePath;
                            INode  type        = g.GetTriplesWithSubjectPredicate(n, dnrType).Select(t => t.Object).FirstOrDefault();
                            if (type == null)
                            {
                                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as there is no dnr:type property specified");
                                continue;
                            }
                            if (type.NodeType == NodeType.Literal)
                            {
                                String handlerType = ((ILiteralNode)type).Value;

                                //First remove any existing registration
                                handlersSection.Handlers.Remove("*", handlerPath);

                                //Then add the new registration
                                handlersSection.Handlers.Add(new HttpHandlerAction(handlerPath, handlerType, "*"));

                                Console.WriteLine("rdfWebDeploy: Deployed the Handler <" + n.ToString() + "> to the web applications Web.Config file");
                            }
                            else
                            {
                                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as the value given for the dnr:type property is not a Literal");
                                continue;
                            }
                        }
                        else
                        {
                            Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy a Handler which is not specified as a URI Node");
                        }
                    }

                    //Deploy Negotiate by File Extension if appropriate
                    if (this._negotiate)
                    {
                        HttpModulesSection modulesSection = config.GetSection("system.web/httpModules") as HttpModulesSection;
                        if (modulesSection == null)
                        {
                            Console.Error.WriteLine("rdfWebDeploy: Error: Unable to access the Modules section of the web applications Web.Config file");
                            return;
                        }
                        modulesSection.Modules.Remove("NegotiateByExtension");
                        modulesSection.Modules.Add(new HttpModuleAction("NegotiateByExtension", "VDS.RDF.Web.NegotiateByFileExtension"));
                        Console.WriteLine("rdfWebDeploy: Deployed the Negotiate by File Extension Module");
                    }

                    Console.WriteLine("rdfWebDeploy: Successfully deployed for IIS Classic Mode");
                }

                //Save the completed Configuration File
                config.Save(ConfigurationSaveMode.Minimal);
                Console.WriteLine();

                //Deploy for IIS Integrated Mode
                if (!this._noIntegratedRegistration)
                {
                    Console.WriteLine("rdfWebDeploy: Attempting deployment for IIS Integrated Mode");
                    Admin.Configuration                  adminConfig        = manager.GetWebConfiguration(this._site, args[1]);
                    Admin.ConfigurationSection           newHandlersSection = adminConfig.GetSection("system.webServer/handlers");
                    Admin.ConfigurationElementCollection newHandlers        = newHandlersSection.GetCollection();

                    foreach (INode n in g.GetTriplesWithPredicateObject(rdfType, httpHandler).Select(t => t.Subject))
                    {
                        if (n.NodeType == NodeType.Uri)
                        {
                            String handlerPath = ((IUriNode)n).Uri.AbsolutePath;
                            INode  type        = g.GetTriplesWithSubjectPredicate(n, dnrType).Select(t => t.Object).FirstOrDefault();
                            if (type == null)
                            {
                                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as there is no dnr:type property specified");
                                continue;
                            }
                            if (type.NodeType == NodeType.Literal)
                            {
                                String handlerType = ((ILiteralNode)type).Value;

                                //First remove any existing registration
                                foreach (Admin.ConfigurationElement oldReg in newHandlers.Where(el => el.GetAttributeValue("name").Equals(handlerPath)).ToList())
                                {
                                    newHandlers.Remove(oldReg);
                                }

                                //Then add the new registration
                                Admin.ConfigurationElement reg = newHandlers.CreateElement("add");
                                reg["name"] = handlerPath;
                                reg["path"] = handlerPath;
                                reg["verb"] = "*";
                                reg["type"] = handlerType;
                                newHandlers.AddAt(0, reg);

                                Console.WriteLine("rdfWebDeploy: Deployed the Handler <" + n.ToString() + "> to the web applications Web.Config file");
                            }
                            else
                            {
                                Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy the Handler <" + n.ToString() + "> as the value given for the dnr:type property is not a Literal");
                                continue;
                            }
                        }
                        else
                        {
                            Console.Error.WriteLine("rdfWebDeploy: Error: Cannot deploy a Handler which is not specified as a URI Node");
                        }

                        //Deploy Negotiate by File Extension if appropriate
                        if (this._negotiate)
                        {
                            Admin.ConfigurationSection newModulesSection = adminConfig.GetSection("system.webServer/modules");
                            if (newModulesSection == null)
                            {
                                Console.Error.WriteLine("rdfWebDeploy: Error: Unable to access the Modules section of the web applications Web.Config file");
                                return;
                            }

                            //First remove the Old Module
                            Admin.ConfigurationElementCollection newModules = newModulesSection.GetCollection();
                            foreach (Admin.ConfigurationElement oldReg in newModules.Where(el => el.GetAttribute("name").Equals("NegotiateByExtension")).ToList())
                            {
                                newModules.Remove(oldReg);
                            }

                            //Then add the new Module
                            Admin.ConfigurationElement reg = newModules.CreateElement("add");
                            reg["name"] = "NegotiateByExtension";
                            reg["type"] = "VDS.RDF.Web.NegotiateByFileExtension";
                            newModules.AddAt(0, reg);

                            Console.WriteLine("rdfWebDeploy: Deployed the Negotiate by File Extension Module");
                        }
                    }

                    manager.CommitChanges();
                    Console.WriteLine("rdfWebDeploy: Successfully deployed for IIS Integrated Mode");
                }
            }
            catch (ConfigurationException configEx)
            {
                Console.Error.WriteLine("rdfWebDeploy: Configuration Error: " + configEx.Message);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("rdfWebDeploy: Error: " + ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
            }
            finally
            {
                if (manager != null)
                {
                    manager.Dispose();
                }
            }
        }
        public static void Main()
        {
            // <Snippet1>
            // Get the Web application configuration.
            System.Configuration.Configuration configuration =
                WebConfigurationManager.OpenWebConfiguration(
                    "/aspnetTest");

            // Get the section.
            HttpModulesSection httpModulesSection =
                (HttpModulesSection)configuration.GetSection(
                    "system.web/httpModules");

            // Get the collection.
            HttpModuleActionCollection modulesCollection =
                httpModulesSection.Modules;

            // </Snippet1>

            // <Snippet2>
            // Create a new HttpModuleActionCollection object.
            HttpModuleActionCollection newModuleActionCollection =
                new HttpModuleActionCollection();

            // </Snippet2>

            //<Snippet3>
            // Create a new module object.

            HttpModuleAction ModuleAction =
                new HttpModuleAction("MyModuleName",
                                     "MyModuleType");

            // Add the module to the collection.
            if (!httpModulesSection.SectionInformation.IsLocked)
            {
                modulesCollection.Add(ModuleAction);
                configuration.Save();
            }

            //</Snippet3>

            //<Snippet4>
            // Set the module object.
            HttpModuleAction ModuleAction1 =
                new HttpModuleAction("MyModule1Name",
                                     "MyModule1Type");
            // Get the module collection index.
            int moduleIndex = modulesCollection.IndexOf(ModuleAction1);

            //</Snippet4>


            //<Snippet5>
            // Set the module object.
            HttpModuleAction ModuleAction2 =
                new HttpModuleAction("MyModule2Name",
                                     "MyModule2Type");

            // Remove the module from the collection.
            if (!httpModulesSection.SectionInformation.IsLocked)
            {
                modulesCollection.Remove(ModuleAction2);
                configuration.Save();
            }

            //</Snippet5>


            //<Snippet6>

            // Remove the module from the collection.
            if (!httpModulesSection.SectionInformation.IsLocked)
            {
                modulesCollection.Remove("TimerModule");
                configuration.Save();
            }

            //</Snippet6>

            //<Snippet7>

            // Remove the module from the collection.
            if (!httpModulesSection.SectionInformation.IsLocked)
            {
                modulesCollection.RemoveAt(0);
                configuration.Save();
            }

            //</Snippet7>

            //<Snippet8>

            // Clear the collection.
            if (!httpModulesSection.SectionInformation.IsLocked)
            {
                modulesCollection.Clear();
                configuration.Save();
            }

            //</Snippet8>
        }