예제 #1
0
 /// <devdoc>
 /// Validates that the WebResource.axd handler is registered in config and actually
 /// points to the correct handler type.
 /// </devdoc>
 private static void EnsureHandlerExistenceChecked()
 {
     // First we have to check that the handler is registered:
     // <add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="True" />
     if (!_handlerExistenceChecked)
     {
         HttpContext       context           = HttpContext.Current;
         IIS7WorkerRequest iis7WorkerRequest = (context != null) ? context.WorkerRequest as IIS7WorkerRequest : null;
         string            webResourcePath   = UrlPath.Combine(HttpRuntime.AppDomainAppVirtualPathString, _webResourceUrl);
         if (iis7WorkerRequest != null)
         {
             // check the IIS <handlers> section by mapping the handler
             string handlerTypeString = iis7WorkerRequest.MapHandlerAndGetHandlerTypeString(method: "GET",
                                                                                            path: UrlPath.Combine(HttpRuntime.AppDomainAppVirtualPathString, _webResourceUrl),
                                                                                            convertNativeStaticFileModule: false, ignoreWildcardMappings: true);
             if (!String.IsNullOrEmpty(handlerTypeString))
             {
                 _handlerExists = (typeof(AssemblyResourceLoader) == BuildManager.GetType(handlerTypeString, true /*throwOnFail*/, false /*ignoreCase*/));
             }
         }
         else
         {
             // check the <httpHandlers> section
             HttpHandlerAction httpHandler = RuntimeConfig.GetConfig(VirtualPath.Create(webResourcePath)).HttpHandlers.FindMapping("GET", VirtualPath.Create(_webResourceUrl));
             _handlerExists = (httpHandler != null) && (httpHandler.TypeInternal == typeof(AssemblyResourceLoader));
         }
         _handlerExistenceChecked = true;
     }
 }
        internal static void WriteHandlerToConfiguration(Configuration config)
        {
            HttpHandlersSection handlers = config.GetSection("system.web/httpHandlers") as HttpHandlersSection;

            foreach (HttpHandlerAction h in handlers.Handlers)
            {
                if (h.Path == HandlerName)
                {
                    return;
                }
            }

            HttpHandlerAction myHandler = new HttpHandlerAction(HandlerName, HandlerType, "*", false);

            handlers.Handlers.Add(myHandler);

            try
            {
                config.Save();
            }
            catch (Exception ex)
            {
                // Gulp
                System.Diagnostics.Debug.Write(ex.ToString());
            }
        }
예제 #3
0
        bool LocateHandler(string verb, string uri)
        {
            var config = WebConfigurationManager.GetSection("system.web/httpHandlers") as HttpHandlersSection;
            HttpHandlerActionCollection handlers = config != null ? config.Handlers : null;
            int count = handlers != null ? handlers.Count : 0;

            if (count == 0)
            {
                return(false);
            }

            for (int i = 0; i < count; i++)
            {
                HttpHandlerAction handler = handlers [i];
                string[]          verbs   = SplitVerbs(handler.Verb);

                if (verbs == null)
                {
                    if (PathMatches(handler, uri))
                    {
                        return(true);
                    }
                    continue;
                }

                for (int j = 0; j < verbs.Length; j++)
                {
                    if (verbs [j] != verb)
                    {
                        continue;
                    }
                    if (PathMatches(handler, uri))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
예제 #4
0
 private static void EnsureHandlerExistenceChecked()
 {
     if (!_handlerExistenceChecked)
     {
         HttpContext       current = HttpContext.Current;
         IIS7WorkerRequest request = (current != null) ? (current.WorkerRequest as IIS7WorkerRequest) : null;
         string            path    = UrlPath.Combine(HttpRuntime.AppDomainAppVirtualPathString, "WebResource.axd");
         if (request != null)
         {
             string str2 = request.MapHandlerAndGetHandlerTypeString("GET", path, false);
             if (!string.IsNullOrEmpty(str2))
             {
                 _handlerExists = typeof(AssemblyResourceLoader) == BuildManager.GetType(str2, true, false);
             }
         }
         else
         {
             HttpHandlerAction action = RuntimeConfig.GetConfig(VirtualPath.Create(path)).HttpHandlers.FindMapping("GET", VirtualPath.Create("WebResource.axd"));
             _handlerExists = (action != null) && (action.TypeInternal == typeof(AssemblyResourceLoader));
         }
         _handlerExistenceChecked = true;
     }
 }
예제 #5
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();
            }
        }
예제 #6
0
파일: Default.aspx.cs 프로젝트: kyvkri/MG
 public static int EnsureWebConfigHandler(Configuration config, string type, string path)
 {
     HttpHandlerAction action = new HttpHandlerAction(path, type, "*");
     HttpHandlersSection hs = (HttpHandlersSection)config.GetSection("system.web/httpHandlers");
     foreach (HttpHandlerAction ha in hs.Handlers) {
         if (ha.Path.ToLower().Trim() == path.ToLower().Trim()) return 0;
     }
     hs.Handlers.Add(action);
     return 1;
 }
예제 #7
0
        public UsingHttpHandlersSection()
        {
            // Process the
            // System.Web.Configuration.HttpHandlersSectionobject.
            try
            {
// <Snippet1>

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

                // Get the section.
                System.Web.Configuration.HttpHandlersSection httpHandlersSection = (System.Web.Configuration.HttpHandlersSection)configuration.GetSection("system.web/httphandlers");

// </Snippet1>

// <Snippet2>

                // Get the handlers.
                System.Web.Configuration.HttpHandlerActionCollection httpHandlers = httpHandlersSection.Handlers;

// </Snippet2>

// <Snippet3>
// Add a new HttpHandlerAction to the Handlers property HttpHandlerAction collection.
                httpHandlersSection.Handlers.Add(new HttpHandlerAction(
                                                     "Calculator.custom",
                                                     "Samples.Aspnet.SystemWebConfiguration.Calculator, CalculatorHandler",
                                                     "GET",
                                                     true));
// </Snippet3>

// <Snippet4>
// Get a HttpHandlerAction in the Handlers property HttpHandlerAction collection.
                HttpHandlerAction httpHandler = httpHandlers[0];

// </Snippet4>

// <Snippet5>
// Change the Path for the HttpHandlerAction.
                httpHandler.Path = "Calculator.custom";
// </Snippet5>

// <Snippet6>
// Change the Type for the HttpHandlerAction.
                httpHandler.Type =
                    "Samples.Aspnet.SystemWebConfiguration.Calculator, CalculatorHandler";
// </Snippet6>

// <Snippet7>
// Change the Verb for the HttpHandlerAction.
                httpHandler.Verb = "POST";
// </Snippet7>

// <Snippet8>
// Change the Validate for the HttpHandlerAction.
                httpHandler.Validate = false;
// </Snippet8>

// <Snippet9>

                // Get the specified handler's index.
                HttpHandlerAction httpHandler2 = new HttpHandlerAction(
                    "Calculator.custom",
                    "Samples.Aspnet.SystemWebConfiguration.Calculator, CalculatorHandler",
                    "GET", true);
                int handlerIndex = httpHandlers.IndexOf(httpHandler2);

// </Snippet9>

// <Snippet10>

// Remove a HttpHandlerAction object
                HttpHandlerAction httpHandler3 = new HttpHandlerAction(
                    "Calculator.custom",
                    "Samples.Aspnet.SystemWebConfiguration.Calculator, CalculatorHandler",
                    "GET", true);
                httpHandlers.Remove(httpHandler3);
// </Snippet10>

// <Snippet11>

                // Remove a HttpHandlerAction object with 0 index.
                httpHandlers.RemoveAt(0);

// </Snippet11>

// <Snippet12>
                // Clear all CustomError objects from the Handlers property HttpHandlerAction collection.
                httpHandlers.Clear();

// </Snippet12>

// <Snippet13>

                // Remove the handler with the specified verb and path.
                httpHandlers.Remove("GET", "*.custom");

// </Snippet13>

                Console.WriteLine("List the Errors collection:");
                int handlerActionCtr = 0;
                foreach (HttpHandlerAction handlerAction in httpHandlersSection.Handlers)
                {
// <Snippet14>
                    string type = handlerAction.Type;
// </Snippet14>
// <Snippet15>
                    string verb = handlerAction.Verb;
// </Snippet15>
// <Snippet16>
                    bool validation = handlerAction.Validate;
// </Snippet16>

                    Console.WriteLine("  {0}: message", ++handlerActionCtr);
                }

                // Update if not locked.
                if (!httpHandlersSection.SectionInformation.IsLocked)
                {
                    configuration.Save();
                    Console.WriteLine("** Configuration updated.");
                }
                else
                {
                    Console.WriteLine("** Could not update, section is locked.");
                }
            }
            catch (System.ArgumentException e)
            {
                // Unknown error.
                Console.WriteLine(e.ToString());
            }
        }
예제 #8
0
 // Methods
 public int IndexOf(HttpHandlerAction action)
 {
 }
예제 #9
0
 public void Remove(HttpHandlerAction action)
 {
 }
예제 #10
0
 public void Add(HttpHandlerAction httpHandlerAction)
 {
 }
	public void Remove(HttpHandlerAction action) {}
	public void Add(HttpHandlerAction httpHandlerAction) {}
	// Methods
	public int IndexOf(HttpHandlerAction action) {}
예제 #14
0
        bool PathMatches(HttpHandlerAction handler, string uri)
        {
            bool result = false;

            string[] handlerPaths = handler.Path.Split(',');
            int      slash        = uri.LastIndexOf('/');
            string   origUri      = uri;

            if (slash != -1)
            {
                uri = uri.Substring(slash);
            }

            SearchPattern sp = null;

            foreach (string handlerPath in handlerPaths)
            {
                if (handlerPath == "*")
                {
                    continue;                     // ignore
                }
                string matchExact = null;
                string endsWith   = null;
                Regex  regEx      = null;

                if (handlerPath.Length > 0)
                {
                    if (handlerPath [0] == '*' && (handlerPath.IndexOf('*', 1) == -1))
                    {
                        endsWith = handlerPath.Substring(1);
                    }

                    if (handlerPath.IndexOf('*') == -1)
                    {
                        if (handlerPath [0] != '/')
                        {
                            HttpContext ctx   = HttpContext.Current;
                            HttpRequest req   = ctx != null ? ctx.Request : null;
                            string      vpath = HttpRuntime.AppDomainAppVirtualPath;

                            if (vpath == "/")
                            {
                                vpath = String.Empty;
                            }

                            matchExact = String.Concat(vpath, "/", handlerPath);
                        }
                    }
                }

                if (matchExact != null)
                {
                    result = matchExact.Length == origUri.Length && origUri.EndsWith(matchExact, StringComparison.OrdinalIgnoreCase);
                    if (result == true)
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
                else if (endsWith != null)
                {
                    result = uri.EndsWith(endsWith, StringComparison.OrdinalIgnoreCase);
                    if (result == true)
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }

                string pattern;
                if (handlerPath.Length > 0 && handlerPath [0] == '/')
                {
                    pattern = handlerPath.Substring(1);
                }
                else
                {
                    pattern = handlerPath;
                }

                if (sp == null)
                {
                    sp = new SearchPattern(pattern, true);
                }
                else
                {
                    sp.SetPattern(pattern, true);
                }

                if (sp.IsMatch(origUri))
                {
                    result = true;
                    break;
                }
            }

            return(result);
        }