Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# mvcsitemapprovider面包屑在URL中的新参数后中断_C#_Asp.net Mvc_Breadcrumbs_Mvcsitemapprovider - Fatal编程技术网

C# mvcsitemapprovider面包屑在URL中的新参数后中断

C# mvcsitemapprovider面包屑在URL中的新参数后中断,c#,asp.net-mvc,breadcrumbs,mvcsitemapprovider,C#,Asp.net Mvc,Breadcrumbs,Mvcsitemapprovider,在我的MVC应用程序中,我们有大约200多个使用网格的页面。最近,我们添加了history.js与网格的集成,在URL中添加了“page”参数,如 这给面包屑带来了问题。如果我的URL为,则在面包屑中显示“主页>管理用户>用户”。但如果URL随页面更改,即面包屑更改为父级,即“管理用户”,其中“管理用户”没有超链接 我的网站地图设计如下: <mvcSiteMapNode title="Manage Users" controller="User" action="ManageUsers

在我的MVC应用程序中,我们有大约200多个使用网格的页面。最近,我们添加了history.js与网格的集成,在URL中添加了“page”参数,如

这给面包屑带来了问题。如果我的URL为,则在面包屑中显示“主页>管理用户>用户”。但如果URL随页面更改,即面包屑更改为父级,即“管理用户”,其中“管理用户”没有超链接

我的网站地图设计如下:

  <mvcSiteMapNode title="Manage Users" controller="User" action="ManageUsers">
    <mvcSiteMapNode title="Users" controller="User" action="ManageUsers" preservedRouteParameters="id">
      <mvcSiteMapNode title="Facilities" controller="User" action="ManageUserFacilities" preservedRouteParameters="id,conf"/>
      <mvcSiteMapNode title="Conversations" controller="User" action="UserConversations" preservedRouteParameters="id,conf"/>
    </mvcSiteMapNode>
    <mvcSiteMapNode title="User Postings" controller="User" action="ManageUserPostings"/>
  </mvcSiteMapNode>
请帮我找到这个问题的逻辑解决方案。

我无法解释(或再现)您看到的尾随斜杠行为,但我确实看到了一个潜在问题

在将节点与传入路由进行匹配时,以下两个节点不明确:

<mvcSiteMapNode title="Manage Users" controller="User" action="ManageUsers">
  <mvcSiteMapNode title="Users" controller="User" action="ManageUsers" preservedRouteParameters="id">
以及您的节点:

<mvcSiteMapNode title="Manage Users" controller="User" action="ManageUsers" route="User_MangageUsers">
  <mvcSiteMapNode title="Users" controller="User" action="ManageUsers" preservedRouteParameters="id">
根据您的路线进行更新

我仍然无法重现这个问题

但是,您的路由配置确实存在问题-即,在单个路由上指定2个可选参数是无效的。这可能与尾部斜杠问题有关,因为当您关闭这两个可选参数时,在生成URL时,结果将包括一个额外的尾部斜杠。在当前路由配置中,
默认
路由是无法访问的执行路径

你可以通过改变你的路线来解决这个问题

routes.MapRoute(
    name: "DefaultwithType",
    url: "{controller}/{action}/{id}/{type}",
    defaults: new { type = UrlParameter.Optional }); 

routes.MapRoute(
    name: "Default", 
    url: "{controller}/{action}", 
    defaults: new { controller = "Home", action = "Index" });
现在:

使用此路由配置,可以通过显式指定路由来消除节点之间的不确定性。这可能是必要的,也可能不是必要的-请尝试先修复节点,然后再修复此节点

<mvcSiteMapNode title="Manage Users" controller="User" action="ManageUsers" route="Default">
  <mvcSiteMapNode title="Users" controller="User" action="ManageUsers" route="DefaultwithType" preservedRouteParameters="id">
节点:

<mvcSiteMapNode title="Manage Users" controller="User" action="ManageUsers" route="Default">
  <mvcSiteMapNode title="Users" controller="User" action="ManageUsers" route="User" preservedRouteParameters="id,page">

现在
用户
路由将优先于
默认
路由。除非提供4段URL,否则
DefaultwithType
路由将不匹配-如果应用程序中的URL为4段,而您不打算调用最后一段
{type}
,则可能需要一些固定段或约束

我还将“页面”包含在参数中。这可能不是必需的,但如果包含它,则应该与请求中是否包含页码相匹配


“MvcSiteMapProvider_AttributesToIgnore”用于在节点上生成路由匹配中未包含的自定义属性。它与忽略传入URL中的值无关。

请发布您的路由配置.routes.MapRoute(名称:“DefaultwithType”,URL:“{controller}/{action}/{id}/{type}”,默认值:new{controller=“Home”,action=“Index”,id=UrlParameter.Optional,type=UrlParameter.Optional} ); MapRoute(名称:“Default”,url:{controller}/{action}/{id}),默认值:new{controller=“Home”,action=“Index”,id=UrlParameter.Optional})这里是routeConfigs:routes.MapRoute(名称:“DefaultwithType”,url:“{controller}/{action}/{id}/{type}”,默认值:new{controller=“Home”,action=“Index”,id=UrlParameter.Optional,type=UrlParameter.Optional});MapRoute(名称:“Default”,url:{controller}/{action}/{id}),默认值:new{controller=“Home”,action=“Index”,id=UrlParameter.Optional});我按照您的建议更新到了v4.6.18,并添加了PreservedRouteParameters=“page”,但没有任何更改。我希望保持不明确,这样当用户单击主链接时,他们会直接移动到子页面,在那里他们可以找到子链接。不想为Manage_用户添加routeMap,因为在这种情况下需要添加很多映射,因为页面参数将有很多不同的页面。如果我删除id=UrlParameter。在“默认”路由中为可选,我会收到不允许目录浏览的错误。但我按照你的指示更改了“DefaultwithType”路线。但结果完全一样,没有变化。URL仍然有userdetail/?page=2,面包屑仍然无法显示当前页面,而不像以前那样显示其父id。@sarojanand-我重新阅读了你的问题,并意识到我无法从中推断出确切的问题是什么。我假设“管理用户”节点用于用户列表(可以分页),而“用户”节点用于查看特定用户。这是配置它的标准方法,它可以与此配置一起使用。但是,既然你描述了行为是什么,但没有描述预期的行为是什么,我只是在猜测这一点。哪个节点的页码应该匹配?
routes.MapRoute(
    name: "DefaultwithType",
    url: "{controller}/{action}/{id}/{type}",
    defaults: new { type = UrlParameter.Optional }); 

routes.MapRoute(
    name: "Default", 
    url: "{controller}/{action}", 
    defaults: new { controller = "Home", action = "Index" });
/User/ManageUsers/1/SomeType - matches DefaultwithType
/User/ManageUsers/1          - matches DefaultwithType
/User/ManageUsers            - matches Default
/User                        - matches Default (with action "Index")
/                            - matches Default (with controller "Home", action "Index")
<mvcSiteMapNode title="Manage Users" controller="User" action="ManageUsers" route="Default">
  <mvcSiteMapNode title="Users" controller="User" action="ManageUsers" route="DefaultwithType" preservedRouteParameters="id">
// Route to force match with "Users" node
routes.MapRoute(
    name: "User",
    url: "User/ManageUsers/{id}",
    defaults: new { controller = "User", action = "ManageUsers" }); 

routes.MapRoute(
    name: "DefaultwithType",
    url: "{controller}/{action}/{id}/{type}"); 

routes.MapRoute(
    name: "Default", 
    url: "{controller}/{action}/{id}", 
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });
<mvcSiteMapNode title="Manage Users" controller="User" action="ManageUsers" route="Default">
  <mvcSiteMapNode title="Users" controller="User" action="ManageUsers" route="User" preservedRouteParameters="id,page">