IEnumerable<HttpHandlerRegistration> GetNativeHandlers() { IEnumerable handlers; try { var configManagerType = Type.GetType("Microsoft.Web.Administration.WebConfigurationManager, " + MICROSOFT_WEB_ADMINISTRATION); var configurationSectionType = Type.GetType("Microsoft.Web.Administration.ConfigurationSection, " + MICROSOFT_WEB_ADMINISTRATION); var method = configManagerType.GetMethod("GetSection", new[] { typeof(string) }); var configSection = method.Invoke(null, new object[] { "system.webServer/handlers" }); handlers = (IEnumerable)configurationSectionType.GetMethod("GetCollection", new Type[0]).Invoke(configSection, null); } catch (Exception) { yield break; } foreach (var handler in handlers) { var attribValueMethod = handler.GetType().GetMethod("GetAttributeValue", new[] { typeof(string) }); var verb = (string)attribValueMethod.Invoke(handler, new object[] { "verb" }); var path = (string)attribValueMethod.Invoke(handler, new object[] { "path" }); var type = (string)attribValueMethod.Invoke(handler, new object[] { "type" }); var handlerReg = new HttpHandlerRegistration(verb, path, type); if (IsHandlerRegistrationValid(handlerReg)) { yield return handlerReg; } } }
IEnumerable <HttpHandlerRegistration> GetNativeHandlers() { IEnumerable handlers; try { var configManagerType = Type.GetType("Microsoft.Web.Administration.WebConfigurationManager, " + MICROSOFT_WEB_ADMINISTRATION); var configurationSectionType = Type.GetType("Microsoft.Web.Administration.ConfigurationSection, " + MICROSOFT_WEB_ADMINISTRATION); var method = configManagerType.GetMethod("GetSection", new[] { typeof(string) }); var configSection = method.Invoke(null, new object[] { "system.webServer/handlers" }); handlers = (IEnumerable)configurationSectionType.GetMethod("GetCollection", new Type[0]).Invoke(configSection, null); } catch (Exception) { yield break; } foreach (var handler in handlers) { var attribValueMethod = handler.GetType().GetMethod("GetAttributeValue", new[] { typeof(string) }); var verb = (string)attribValueMethod.Invoke(handler, new object[] { "verb" }); var path = (string)attribValueMethod.Invoke(handler, new object[] { "path" }); var type = (string)attribValueMethod.Invoke(handler, new object[] { "type" }); var handlerReg = new HttpHandlerRegistration(verb, path, type); if (IsHandlerRegistrationValid(handlerReg)) { yield return(handlerReg); } } }
public bool IsHandlerRegistrationValid(HttpHandlerRegistration registration) { return !string.IsNullOrEmpty(registration.Path) && registration.Path != "*" && !registration.Type.Contains(typeof(DefaultHttpHandler).FullName); }
protected static bool IsHandlerRegistrationValid(HttpHandlerRegistration registration) { return(!string.IsNullOrEmpty(registration.Path) && registration.Path != "*" && !registration.Type.Contains(typeof(DefaultHttpHandler).FullName)); }