private void LoadRouteData(IActionDescriptorCollectionProvider routeProvider, IRouteDataService routeDataService, IPluginTypesService pluginTypesService) { List <Type> badeggAttributes = pluginTypesService.GetPluginTypesWithAttribute <BadEggAttribute>(); if (badeggAttributes.Count > 0) { // Cycle through all classes and methods which have the bad egg attribute foreach (Type type in badeggAttributes) { // is it a class attribute BadEggAttribute attribute = (BadEggAttribute)type.GetCustomAttributes(true) .Where(a => a.GetType() == typeof(BadEggAttribute)).FirstOrDefault(); if (attribute != null) { string route = routeDataService.GetRouteFromClass(type, routeProvider); if (String.IsNullOrEmpty(route)) { continue; } _managedRoutes.Add(new ManagedRoute($"{route.ToLower()}", attribute.ValidateQueryFields, attribute.ValidateFormFields)); } // look for specific method disallows foreach (MethodInfo method in type.GetMethods()) { attribute = (BadEggAttribute)method.GetCustomAttributes(true) .Where(a => a.GetType() == typeof(BadEggAttribute)).FirstOrDefault(); if (attribute != null) { string route = routeDataService.GetRouteFromMethod(method, routeProvider); if (String.IsNullOrEmpty(route)) { continue; } _managedRoutes.Add(new ManagedRoute($"{route.ToLower()}", attribute.ValidateQueryFields, attribute.ValidateFormFields)); } } } } }
private void LoadSpiderData(IActionDescriptorCollectionProvider routeProvider, IRouteDataService routeDataService, IPluginTypesService pluginTypesService) { string spiderTextFile = String.Empty; List <Type> spiderAttributes = pluginTypesService.GetPluginTypesWithAttribute <DenySpiderAttribute>(); if (spiderAttributes.Count == 0) { spiderTextFile = "# Allow all from Spider.Plugin\r\n\r\nUser-agent: *"; } else { // Cycle through all classes and methods which have the spider attribute foreach (Type type in spiderAttributes) { // is it a class attribute DenySpiderAttribute attribute = (DenySpiderAttribute)type.GetCustomAttributes(true) .Where(a => a.GetType() == typeof(DenySpiderAttribute)).FirstOrDefault(); if (attribute != null) { string route = routeDataService.GetRouteFromClass(type, routeProvider); if (String.IsNullOrEmpty(route)) { continue; } if (!String.IsNullOrEmpty(attribute.Comment)) { spiderTextFile += $"# {attribute.Comment}\r\n\r\n"; } spiderTextFile += $"User-agent: {attribute.UserAgent}\r\n"; spiderTextFile += $"Disallow: /{route}/\r\n\r\n"; _deniedSpiderRoutes.Add(new DeniedRoute($"/{route.ToLower()}/", attribute.UserAgent)); } // look for specific method disallows foreach (MethodInfo method in type.GetMethods()) { attribute = (DenySpiderAttribute)method.GetCustomAttributes(true) .Where(a => a.GetType() == typeof(DenySpiderAttribute)).FirstOrDefault(); if (attribute != null) { string route = routeDataService.GetRouteFromMethod(method, routeProvider); if (String.IsNullOrEmpty(route)) { continue; } if (!String.IsNullOrEmpty(attribute.Comment)) { spiderTextFile += $"# {attribute.Comment}\r\n\r\n"; } spiderTextFile += $"User-agent: {attribute.UserAgent}\r\n"; spiderTextFile += $"Disallow: {route}\r\n\r\n"; _deniedSpiderRoutes.Add(new DeniedRoute($"{route.ToLower()}", attribute.UserAgent)); } } } } _spiderData = Encoding.UTF8.GetBytes(spiderTextFile); }