2014-07-08 2 views
2

내 블로그 사이트에 asp.net mvc sitemap을 사용하고 있는데 Mvc.sitemap xml 파일에서 동적 URL 및 제목을 제공하려고 할 때 한 가지 문제가 발생합니다. DynamicNodeProvider를 사용하고 싶지 않습니다. 모든 블로그를 반복해야하므로 내 애플리케이션이 느려지니까요.동적 URL 및 제목 Asp.net mvc 사이트 맵

내 컨트롤러와 액션 코드는 같다 :

public class ArticlesController : Controller 
{ 

    public ActionResult Index(int id, string title) 
    { 
    } 
} 

Mvc.sitemap의 XML은 아래와 같습니다 : Mvc.sitemap의 XML 위의 대담이 mvcSiteMapNode 제목과 URL을 강조

<?xml version="1.0" encoding="utf-8" ?> 
<mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0" 
     xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0 MvcSiteMapSchema.xsd"> 
<mvcSiteMapNode title="Home" controller="Home" action="Index"> 
<mvcSiteMapNode title="DevSection" controller="DevSection" action="Index" key="DevSection"> 
    <mvcSiteMapNode title="Articles" controller="DevSection" action="Article" key="Articles"> 
    <mvcSiteMapNode title="" controller="Articles" action="Index" url="" /> 
    </mvcSiteMapNode> 
    </mvcSiteMapNode> 
</mvcSiteMapNode> 
</mvcSiteMap> 

에서

가 비어 있습니다 동적 빌드 URL을 전달하고 다음과 같이 출력을 표시하는 방법을 알지 못해서입니다.

도와주세요, 어떻게 이것을 할 수 있습니까? 미리 감사드립니다.

+0

http : // joelabrahamsson.com/xml-sitemap-with-aspnet-mvc /' –

+0

을 사용해보십시오. – user3573658

+0

이 도움이됩니까? –

답변

3

동적 탐색 경로를 작성하려는 경우 preservedRouteParameters를 사용하여 단일 노드가 모든 기사의 경로 값에 일치하도록 할 수 있습니다.

<?xml version="1.0" encoding="utf-8" ?> 
<mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0" 
     xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0 MvcSiteMapSchema.xsd"> 
    <mvcSiteMapNode title="Home" controller="Home" action="Index"> 
     <mvcSiteMapNode title="DevSection" controller="DevSection" action="Index" key="DevSection"> 
      <mvcSiteMapNode title="Articles" controller="DevSection" action="Article" key="Articles"> 
       <mvcSiteMapNode title="" controller="Articles" action="Index" preservedRouteParameters="id,title" /> 
      </mvcSiteMapNode> 
     </mvcSiteMapNode> 
    </mvcSiteMapNode> 
</mvcSiteMap> 

그런 다음 SiteMapTitle 속성을 사용하여 노드의 제목을 동적으로 변경할 수 있습니다.

public class ArticlesController : Controller 
{ 
    [SiteMapTitle("title")] 
    public ActionResult Index(int id, string title) 
    { 
    } 
} 

은 또한 메뉴에서 "동적 URL"에 노드를 숨기기 위해 FitleredSiteMapNodeVisibilityProvider을 사용해야 할 수도 있습니다.

그러나 내장형 sitemaps XML 기능을 사용하여 기사가 검색 엔진에서 색인이 생성되도록하려면 DynamicNodeProvider를 사용하는 것이 좋습니다.

이 주제에 대한 자세한 내용은 How to Make MvcSiteMapProvider Remember a User's Position을 참조하십시오.

+0

고마워, 그것은 나를 위해 작동합니다. – user3573658

+0

고마워, 나를 위해 일했다. 실제로 SiteMapTitle 특성을 추가 할 필요가 없었으며 여전히 작동했습니다. –