无法解析的网址为区域站点地图结点 [英] Could not resolve URL for sitemap node in Area

查看:167
本文介绍了无法解析的网址为区域站点地图结点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索互联网<一个href=\"http://stackoverflow.com/questions/9643397/mvcsitemapprovider-$p$pserved-route-parameter-gives-error-could-not-resolve-url\">I发现了类似的问题的,但我只与项目的其他地区发生的节点

错误


  

无法解析的网址站点地图结点宪章德Interveniência这
  重新在控制器processo presents行动carta_interveniencia。确保
  对于此站点地图节点的路由就可以解决,而其
  默认值允许解析URL当前站点地图节点。


网站

 &LT; mvcSiteMapNode标题=Cadastros点击=false的角色=*&GT;    &LT; mvcSiteMapNode标题=Processos控制器=processos行动=指数&GT;
        &LT; mvcSiteMapNode标题=诺行动=新生/&GT;
        &LT; mvcSiteMapNode标题=Editar行动=editardynamicNodeProvider =CreditoImobiliarioBB.Web.Infra.Sitemap.ProcessosDynamicNodeProvider,CreditoImobiliarioBB.Web/&GT;
        &LT; mvcSiteMapNode标题=事件详细信息行动=事件详细信息preservedRouteParameters =IDdynamicNodeProvider =CreditoImobiliarioBB.Web.Infra.Sitemap.ProcessosDynamicNodeProvider,CreditoImobiliarioBB.Web&GT;
            &LT; mvcSiteMapNode标题=Documentos键=ProcessoDocumentos2点击=假面积=Documentos控制器=processo&GT;
                &LT; mvcSiteMapNode标题=宪章德InterveniênciapreservedRouteParameters =ID行动=carta_interveniencia&GT;&LT; / mvcSiteMapNode&GT;
            &LT; / mvcSiteMapNode&GT;
        &LT; / mvcSiteMapNode&GT;    &LT; / mvcSiteMapNode&GT;

域名注册

 公共类DocumentosAreaRegistration:AreaRegistration
{
    公众覆盖字符串AREANAME
    {
        得到
        {
            返回Documentos
        }
    }    公共覆盖无效RegisterArea(AreaRegistrationContext上下文)
    {
        context.MapRoute(
            名称:Documentos
            网址:{控制器} / {ID} /这份执行/ {}行动,
            默认值:空,
            限制:新{ID = @^ \\ D + $},
            命名空间:新的String [] {CreditoImobiliarioBB.Web.Areas.Documentos}
        );
    }
}


解决方案

解析器的缺省实现的行为这种方式。它试图找到基于关正是你在你的网站地图的路线。由于您的Sitemap没有id参数,你必须上一个约束,该路由没有发现和解析器抛出异常。然而,有没有真正的理由解析器具有加载时站点地图来解决所有的URL。

您可以创建自己的解析器和注册与网站地图。复制和默认的粘贴到自己的类。附近的默认code的底部是这样的:

 如果(string.IsNullOrEmpty(的returnValue))
{
    抛出新UrlResolverException(的String.Format(Messages.CouldNotResolve,mvcSiteMapNode.Title,动作,控制器,mvcSiteMapNode.Route ??));
} _urlkey =键;
_url =的returnValue;
返回的returnValue;

更改了code这样:

 如果(string.IsNullOrEmpty(的returnValue))
{
    返回Guid.NewGuid()的ToString()。
} _urlkey =键;
_url =的returnValue;
返回的returnValue;

Searching the internet I found a similar problem, but mine occurs only with nodes in other areas of the project.

Error

Could not resolve URL for sitemap node Carta de Interveniência which represents action carta_interveniencia in controller processo. Ensure that the route for this sitemap node can be resolved and that its default values allow resolving the URL for the current sitemap node.

Sitemap

<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>

Area registration

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" }
        );
    }
}

解决方案

The default implementation of the resolver behaves this way. It tries to locate the route based off exactly what you have in your sitemap. Since your sitemap does not have the id parameter and you have a constraint on that, the route is not found and the resolver throws an exception. However, there is no real reason the resolver has to resolve every URL when it loads the sitemap.

You can create your own resolver and register that with the sitemap. Copy and paste the default one into your own class. Near the bottom of the default code is this:

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

 _urlkey = key;
_url = returnValue;
return returnValue;

Change that code to this:

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

 _urlkey = key;
_url = returnValue;
return returnValue;

这篇关于无法解析的网址为区域站点地图结点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆