在我们的网站上,此错误每5分钟出现一次。
而且我不知道它从哪里来。
谁能帮助我们。
我们需要没有这个错误的robots.txt。

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



该方法是在调用此方法时自动生成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分钟响一声。我们使用Amazon服务器进行CDN,从那里获取图像。

亚马逊是否有可能将此URL称为“http://www.xyzName.com/content/images/thumbs/robots.txt”网址?

最佳答案

从您的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="" />

希望这可以帮助!

关于c# - System.Web.Routing.UrlRoutingModule不实现IHttpHandlerFactory或IHttpHandler,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40127625/

10-10 03:46