System.Web.Routing.UrlRoutingModule 没有实现 IHttpHandlerFactory 或 IHttpHandler

System.Web.Routing.UrlRoutingModule does not implement IHttpHandlerFactory or IHttpHandler

在我们的网站中,此错误每 5 分钟出现一次。 我不知道它是从哪里来的。 任何人都可以帮助我们吗? 我们需要 robots.txt 没有这个错误。

我们的应用自动调用http://www.xyzName.com/content/images/thumbs/robots.txt 并在下方显示异常

System.Web.Routing.UrlRoutingModule does not implement IHttpHandlerFactory or IHttpHandler.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

此方法调用时自动生成robots.txt文件。但问题出在应用程序 robots.txt 中的某个地方自动调用。

  public ActionResult RobotsTextFile()
            {
                //Default Code blocked by Nilesh
                if (_storeContext.CurrentStore.Url.Contains("tk"))
                {
                    const string newLine = "\r\n"; //Environment.NewLine
                    var sb = new StringBuilder();
                    sb.Append("User-agent: *");
                    sb.Append(newLine);
                    sb.Append("Disallow: /");
                    Response.ContentType = "text/plain";
                    Response.Write(sb.ToString());
                }
                else
                {
                    var disallowPaths = new List<string>
                                        {
                                            "/bin/",
                                            "/content/files/",
                                            "/content/files/exportimport/",
                                            "/country/getstatesbycountryid",
                                            "/install",
                                            "/setproductreviewhelpfulness",
                                        };
                    var localizableDisallowPaths = new List<string>
                                                   {
                                                       "/addproducttocart/catalog/",
                                                       "/addproducttocart/details/",
                                                       "/backinstocksubscriptions/manage",
                                                       "/boards/forumsubscriptions",
                                                       "/boards/forumwatch",
                                                       "/boards/postedit",
                                                       "/boards/postdelete",
                                                       "/boards/postcreate",
                                                       "/boards/topicedit",
                                                       "/boards/topicdelete",
                                                       "/boards/topiccreate",
                                                       "/boards/topicmove",
                                                       "/boards/topicwatch",
                                                       "/cart",
                                                       "/checkout",
                                                       "/checkout/billingaddress",
                                                       "/checkout/completed",
                                                       "/checkout/confirm",
                                                       "/checkout/shippingaddress",
                                                       "/checkout/shippingmethod",
                                                       "/checkout/paymentinfo",
                                                       "/checkout/paymentmethod",
                                                       "/clearcomparelist",
                                                       "/compareproducts",
                                                       "/customer/avatar",
                                                       "/customer/activation",
                                                       "/customer/addresses",
                                                       "/customer/changepassword",
                                                       "/customer/checkusernameavailability",
                                                       "/customer/downloadableproducts",
                                                       "/customer/info",
                                                       "/deletepm",
                                                       "/emailwishlist",
                                                       "/inboxupdate",
                                                       "/newsletter/subscriptionactivation",
                                                       "/onepagecheckout",
                                                       "/order/history",
                                                       "/orderdetails",
                                                       "/passwordrecovery/confirm",
                                                       "/poll/vote",
                                                       "/privatemessages",
                                                       "/returnrequest",
                                                       "/returnrequest/history",
                                                       "/rewardpoints/history",
                                                       "/sendpm",
                                                       "/sentupdate",
                                                       "/shoppingcart/productdetails_attributechange",
                                                       "/subscribenewsletter",
                                                       "/topic/authenticate",
                                                       "/viewpm",
                                                       "/uploadfileproductattribute",
                                                       "/uploadfilecheckoutattribute",
                                                       "/wishlist",
                                                   };


                    const string newLine = "\r\n"; //Environment.NewLine
                    var sb = new StringBuilder();
                    sb.Append("User-agent: *");
                    sb.Append(newLine);
                    //sitemaps
                    if (_localizationSettings.SeoFriendlyUrlsForLanguagesEnabled)
                    {
                        //URLs are localizable. Append SEO code
                        foreach (var language in _languageService.GetAllLanguages(storeId: _storeContext.CurrentStore.Id))
                        {
                            sb.AppendFormat("Sitemap: {0}{1}/sitemap.xml", _storeContext.CurrentStore.Url, language.UniqueSeoCode);
                            sb.Append(newLine);
                        }
                    }
                    else
                    {
                        //localizable paths (without SEO code)
                        sb.AppendFormat("Sitemap: {0}sitemap.xml", _storeContext.CurrentStore.Url);
                        sb.Append(newLine);
                    }

                    //usual paths
                    foreach (var path in disallowPaths)
                    {
                        sb.AppendFormat("Disallow: {0}", path);
                        sb.Append(newLine);
                    }
                    //localizable paths (without SEO code)
                    foreach (var path in localizableDisallowPaths)
                    {
                        sb.AppendFormat("Disallow: {0}", path);
                        sb.Append(newLine);
                    }
                    if (_localizationSettings.SeoFriendlyUrlsForLanguagesEnabled)
                    {
                        //URLs are localizable. Append SEO code
                        foreach (var language in _languageService.GetAllLanguages(storeId: _storeContext.CurrentStore.Id))
                        {
                            foreach (var path in localizableDisallowPaths)
                            {
                                sb.AppendFormat("Disallow: {0}{1}", language.UniqueSeoCode, path);
                                sb.Append(newLine);
                            }
                        }
                    }
                    Response.ContentType = "text/plain";
                    Response.Write(sb.ToString());
                }
                return null;
            }

并且在 RouteProvider 中,我们添加下面一行来映射路线。

 routes.MapRoute("robots.txt","robots.txt",new { controller = "Common", action ="RobotsTextFile" },new[] { "Nop.Web.Controllers" });

每 5 分钟播放一次。我们使用亚马逊服务器作为 CDN,从那里获取图像。

有没有可能亚马逊称这个为'http://www.xyzName.com/content/images/thumbs/robots.txt'url?

从您的 web.config 中删除(或注释掉)这一行用于生成 robot.txt

<add name="RobotsTxt" path="robots.txt" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />

并取消注释以下行

<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />

希望对您有所帮助!

我在最近发布的 Web API 之后遇到了同样的问题,我最近更改了程序集名称。我没有 robots.txt 文件,所以上面的答案与我无关。不管怎样,作为解决方案,我只是简单地清理了服务器上的文件夹并重新发布。

我在新部署到 Server 2016 时也遇到了这个问题。最后,我实际上注释掉了 URLRoutingModule 的处理程序映射并且它起作用了。我的猜测是它与机器级别上已经设置的内容冲突。

    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
        <handlers>
            <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
            <remove name="OPTIONSVerbHandler" />
            <remove name="TRACEVerbHandler" />
            <!--<remove name="UrlRoutingModule-4.0"/>
            <add name="UrlRoutingModule-4.0" path="*" verb="*" type="System.Web.Routing.UrlRoutingModule" preCondition=""/>-->
            <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
    </system.webServer>