2012-10-18 30 views
1

正在搜索互聯網I found a similar problem,但只有項目其他區域中的節點發生。無法解析區域中的站點地圖節點的URL

錯誤

無法解析URL的站點地圖結點憲章德Interveniência這 代表控制器processo行動carta_interveniencia。確保 可以解析此站點地圖節點的路由,並確定其默認值爲 ,從而可以解析當前站點地圖節點的URL。

網站地圖

<mvcSiteMapNode title="Cadastros" clickable="false" roles="*" > 

    <mvcSiteMapNode title="Processos" controller="processos" action="index"> 
     <mvcSiteMapNode title="Novo" action="novo" /> 
     <mvcSiteMapNode title="Editar" action="editar" dynamicNodeProvider="CreditoImobiliarioBB.Web.Infra.Sitemap.ProcessosDynamicNodeProvider, CreditoImobiliarioBB.Web" /> 
     <mvcSiteMapNode title="Detalhes" action="detalhes" preservedRouteParameters="id" dynamicNodeProvider="CreditoImobiliarioBB.Web.Infra.Sitemap.ProcessosDynamicNodeProvider, CreditoImobiliarioBB.Web"> 
      <mvcSiteMapNode title="Documentos" key="ProcessoDocumentos2" clickable="false" area="Documentos" controller="processo"> 
       <mvcSiteMapNode title="Carta de Interveniência" preservedRouteParameters="id" action="carta_interveniencia"></mvcSiteMapNode> 
      </mvcSiteMapNode> 
     </mvcSiteMapNode> 

    </mvcSiteMapNode> 

區登記

public class DocumentosAreaRegistration : AreaRegistration 
{ 
    public override string AreaName 
    { 
     get 
     { 
      return "Documentos"; 
     } 
    } 

    public override void RegisterArea(AreaRegistrationContext context) 
    { 
     context.MapRoute(
      name: "Documentos", 
      url: "{controller}/{id}/documento/{action}", 
      defaults: null, 
      constraints: new { id = @"^\d+$" }, 
      namespaces: new string[] { "CreditoImobiliarioBB.Web.Areas.Documentos" } 
     ); 
    } 
} 

回答

2

解析器的缺省實現的行爲這種方式。它試圖根據您在站點地圖中的內容來定位路線。由於您的站點地圖沒有id參數,並且對此有約束,因此找不到路由並且解析器會引發異常。但是,解析器在加載站點地圖時不得不解析每個URL,因此沒有真正的原因。

您可以創建自己的解析器並將其註冊到站點地圖。複製並粘貼默認教程到您自己的課程中。附近的默認代碼底部是這樣的:

if (string.IsNullOrEmpty(returnValue)) 
{ 
    throw new UrlResolverException(string.Format(Messages.CouldNotResolve, mvcSiteMapNode.Title, action, controller, mvcSiteMapNode.Route ?? "")); 
} 

_urlkey = key; 
_url = returnValue; 
return returnValue; 

更改代碼這樣:

if (string.IsNullOrEmpty(returnValue)) 
{ 
    return Guid.NewGuid().ToString(); 
} 

_urlkey = key; 
_url = returnValue; 
return returnValue;