2012-09-28 19 views
6

Tôi vừa xuất bản một trang web mà tôi đã tạo bằng cách sử dụng các loại cây ăn quả. Tôi đã thêm sitemap.xml vào thư mục gốc nhưng không thể truy cập nó qua trình duyệt. Tôi đoán rằng tôi có thể cần phải sửa đổi tập tin web.config nhưng tôi không chắc chắn như thế nào.sietmap.xml không thể truy cập được trong một trang web được tạo bằng vườn cây ăn quả. Làm thế nào để sửa chữa nó?

EDIT: Đây là cấu hình web của tôi. Tôi không biết làm thế nào để định dạng nó đúng ở đây. Tôi truy cập sitemap.xml tại woodworkingoc.com/sitemap.xml nhưng được 404.

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    Note: As an alternative to hand editing this file you can use the 
    web admin tool to configure settings for your application. Use 
    the Website->Asp.Net Configuration option in Visual Studio. 
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
    \Windows\Microsoft.Net\Framework\v2.x\Config 
--> 
<configuration> 
    <configSections> 
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor"> 
     <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor" requirePermission="false" /> 
     <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor" requirePermission="false" /> 
    </sectionGroup> 
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" /> 
    </configSections> 
    <appSettings> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="log4net.Config" value="Config\log4net.config" /> 
    </appSettings> 
    <system.web.webPages.razor> 
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
    <pages pageBaseType="Orchard.Mvc.ViewEngines.Razor.WebViewPage"> 
     <namespaces> 
     <add namespace="System.Web.Mvc" /> 
     <add namespace="System.Web.Mvc.Ajax" /> 
     <add namespace="System.Web.Mvc.Html" /> 
     <add namespace="System.Web.Routing" /> 
     <add namespace="System.Web.WebPages" /> 
     <add namespace="System.Linq" /> 
     <add namespace="System.Collections.Generic" /> 
     <add namespace="Orchard.Mvc.Html" /> 
     </namespaces> 
    </pages> 
    </system.web.webPages.razor> 
    <!-- 
     Set default transaction timeout to 30 minutes so that interactive debugging 
     is easier (default timeout is less than one minute) 
    --> 
    <system.transactions> 
    <defaultSettings timeout="00:30:00" /> 
    </system.transactions> 
    <system.web> 
    <!--<trust level="Medium" originUrl="" />--> 
    <httpRuntime requestValidationMode="2.0" maxRequestLength="102400" executionTimeout="360" /> 
    <!-- 
      Set compilation debug="true" to insert debugging 
      symbols into the compiled page. Because this 
      affects performance, set this value to true only 
      during development. 
    --> 
    <compilation debug="false" targetFramework="4.0" batch="true" numRecompilesBeforeAppRestart="250" optimizeCompilations="true"> 
     <buildProviders> 
     <add extension=".csproj" type="Orchard.Environment.Extensions.Compilers.CSharpExtensionBuildProviderShim" /> 
     </buildProviders> 
     <assemblies> 
     <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> 
     <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> 
     <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> 
     <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> 
     <remove assembly="System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
     <remove assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
     <remove assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     <remove assembly="System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
     <remove assembly="System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     <remove assembly="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
     <remove assembly="System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
     <remove assembly="System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     <remove assembly="System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     <remove assembly="System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     <remove assembly="System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
     <remove assembly="System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
     <remove assembly="System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
     <remove assembly="System.ServiceModel.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
     <remove assembly="System.WorkflowServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
     <remove assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
     <remove assembly="System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     <remove assembly="System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
     </assemblies> 
    </compilation> 
    <!-- 
      The <authentication> section enables configuration 
      of the security authentication mode used by 
      ASP.NET to identify an incoming user. 
    --> 
    <authentication mode="Forms"> 
     <forms loginUrl="~/Users/Account/AccessDenied" timeout="2880" /> 
    </authentication> 
    <!-- 
      The <customErrors> section enables configuration 
      of what to do if/when an unhandled error occurs 
      during the execution of a request. Specifically, 
      it enables developers to configure html error pages 
      to be displayed in place of a error stack trace. 
    --> 
    <customErrors mode="On"> 
     <error statusCode="404" reirect="/" /> 
    </customErrors> 
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"> 
     <namespaces> 
     <add namespace="System.Web.Mvc" /> 
     <add namespace="System.Web.Mvc.Ajax" /> 
     <add namespace="System.Web.Mvc.Html" /> 
     <add namespace="System.Web.Routing" /> 
     <add namespace="System.Linq" /> 
     <add namespace="System.Collections.Generic" /> 
     <add namespace="Orchard.Mvc.Html" /> 
     </namespaces> 
    </pages> 
    <httpHandlers> 
     <!-- see below --> 
     <clear /> 
     <add path="robots.txt" verb="GET" type="System.Web.StaticFileHandler" /><!--allow sitemap.xml and robots.txt to be served--> 
     <add path="/sitemap.xml" verb="GET" type="System.Web.StaticFileHandler" /> 
     <add path="*" verb="*" type="System.Web.HttpNotFoundHandler" /> 
    </httpHandlers> 
    <httpModules> 
     <add name="WarmupHttpModule" type="Orchard.WarmupStarter.WarmupHttpModule, Orchard.WarmupStarter, Version=1.0.20, Culture=neutral" /> 
    </httpModules> 
    </system.web> 
    <!-- 
     The system.webServer section is required for running ASP.NET AJAX under Internet 
     Information Services 7.0. It is not necessary for previous version of IIS. 
    --> 
    <system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <remove name="WarmupHttpModule" /> 
     <add name="WarmupHttpModule" type="Orchard.WarmupStarter.WarmupHttpModule, Orchard.WarmupStarter, Version=1.0.20, Culture=neutral" /> 
    </modules> 
    <handlers accessPolicy="Script"> 
     <!-- clear all handlers, prevents executing code file extensions, prevents returning any file contents --> 
     <clear /> 
     <!--add entries for sitemap.xml and robots.txt--> 
     <add name="Robots" path="robots.txt" verb="GET" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" /> 
     <add name="SiteMap" path="/sitemap.xml" verb="GET" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" /> 
     <!-- Return 404 for all requests via managed handler. The url routing handler will substitute the mvc request handler when routes match. --> 
     <add name="NotFound" path="*" verb="*" type="System.Web.HttpNotFoundHandler" preCondition="integratedMode" requireAccess="Script" /> 
    </handlers> 
    <!-- Prevent IIS 7.0 from returning a custom 404/500 error page of its own --> 
    <httpErrors existingResponse="PassThrough" /> 
    </system.webServer> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <probing privatePath="App_Data/Dependencies" /> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0" newVersion="3.0.0.0" /> 
     <bindingRedirect oldVersion="2.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.WebPages.Deployment" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="2.0.0.0" newVersion="1.0.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <system.data> 
     <DbProviderFactories> 
      <remove invariant="System.Data.SqlServerCe.4.0" /> 
      <add invariant="System.Data.SqlServerCe.4.0" name="Microsoft® SQL Server® Compact 4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" /> 
     </DbProviderFactories> 
    </system.data> 
</configuration> 

Trả lời

12

Trong phần <system.web> của web.config, hãy chắc chắn bạn có một mục nhập cho sitemap.xml bên trong <httpHandlers> khối:

<httpHandlers> 
    <!-- see below --> 
    <clear /> 
    <add path="robots.txt" verb="GET" type="System.Web.StaticFileHandler" /> 
    <add path="SiteMap.xml" verb="GET" type="System.Web.StaticFileHandler" /> 
    <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/> 
</httpHandlers> 

Ngoài ra hãy chắc chắn rằng bạn có một mục trong system.webServer/xử lý mà cho phép sitemap.xml:

<system.webServer> 
    <handlers accessPolicy="Script,Read"> 
    <!-- clear all handlers, prevents executing code file extensions, prevents returning any file contents --> 
    <clear/> 
    <add name="Robots" path="robots.txt" verb="GET" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" /> 
    <add name="SiteMap" path="SiteMap.xml" verb="GET" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" /> 
    <!-- Return 404 for all requests via managed handler. The url routing handler will substitute the mvc request handler when routes match. --> 
    <add name="NotFound" path="*" verb="*" type="System.Web.HttpNotFoundHandler" preCondition="integratedMode" requireAccess="Script"/> 
</handlers> 

Các mod này cho phép các tệp tĩnh như sitemap.xml được phân phát công khai.

+0

Tôi sẽ thử. Cảm ơn! – Mr1159pm

+0

FOr một số lý do nó không hoạt động – Mr1159pm

+0

Bạn có thể dán web.config của mình không. Điều gì xảy ra khi bạn truy cập sitemap.xml? Bạn đang cố gắng truy cập url ở đâu? –

5

Cá nhân tôi thích sử dụng Advanced Sitemap module để tạo ra bản đồ website. Nó cũng phải quan tâm đến sự độc hại của tập tin sitemap.xml. Bạn có thể xem các nguồn của nó và rất có thể bạn sẽ tìm thấy câu trả lời cho câu hỏi của mình.

+0

Tôi đã xem xét trước nhưng nó chỉ hoạt động với 1.4. Cảm ơn lời khuyên! – Mr1159pm

+0

Tôi đã nâng cấp trang web của mình hôm nay từ Orchard 1.4.0 lên 1.5.1 và mô-đun hoạt động hoàn toàn tốt. –

2

Để thêm robots.txt, httpHandlers không cần thiết vì Orchard đang ở chế độ Tích hợp. Đặt trong web.config Orchard trong xử lý một phần kịch bản, đọc:

<handlers accessPolicy="Script,Read"> 

và thêm sau khi phần <clear/> hai dòng sau:

<add name="Robots" path="robots.txt" verb="*" type="System.Web.StaticFileHandler" preCondition="integratedMode" resourceType="File" requireAccess="Read"/> 
<add name="Sitemap" path="sitemap.xml" verb="*" type="System.Web.StaticFileHandler" preCondition="integratedMode" resourceType="File" requireAccess="Read"/> 

Tôi đang sử dụng Orchard 1.7.2

0

Nếu ai đó đang tìm kiếm câu hỏi này để tìm ra cách thiết lập robots.txt chỉ (không có sitemap.xml) thì bạn có thể sử dụng một Orchard Robots Module đơn giản. Nó cung cấp một cách dễ dàng để thiết lập nội dung robots.txt mà không cần chỉnh sửa web.config hoặc bất kỳ nội dung nào.

Các vấn đề liên quan