网站地图行为 [英] SiteMap Behaviour

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

问题描述

我已经通过MS文档的负载好好看看才发现树视图结构来使用站点地图。我不认为任何人的了解它是如何可能有地图导航的文件夹状结构?取例如一个结构如下

I've had a good look through a load of MS documentation only to find a tree view like structure to the use of sitemaps. I don't suppose anyone's aware of how it's possible to have a folder-like structure for sitemap navigation? Take for example a structure as follows

Home
   About
      Me.aspx
      MyFamily.aspx
      MyPets.aspx
   Contact
      Telephone.aspx
      Email.aspx
 Disclaimer.aspx

关于和联系将是文件夹,但该网站地图是从来没有在一个页面上层次。所以,我有我的两个菜单项根页,一会是家,它就像一个文件夹,深入到有关与接触菜单,另一种是在页面的链接的免责声明。我希望能够在首页点击其中将刷新菜单,其中包含的链接关于和联系隐藏家和免责声明干脆。

The "About" and "Contact" would be folders, but the sitemap is never hierarchical on a single page. So, I would have my root page with two menu items, one would be "Home" which acts like a folder to drill down into the about and contact menus, and the other is a link to the page for the disclaimer. I want to be able to click on Home which will reload the menu with the links for "About" and "Contact" and hide "Home" and "Disclaimer" altogether.

Home >
Disclaimer

然后在家里点击,你会得到

Then click on home and you would get

About >
Contact >

然后在点击你的时候会得到

Then when clicking on about you'd get

Me
My Family
My Pets

每一个菜单将有一个涨菜单回来了一个文件夹。

Every menu would have an "up" menu to come back out a folder.

我看不到那里是一个简单的解决方案,但目前我们使用的是在不同的文件夹中所有在我们的web应用程序的静态HTML页面。这一点需要改变,你可以想像。

I can't see there being an easy solution, but at the moment we use static html pages that are in different folders all over our web application. This is something that needs changing as you can well imagine.

任何想法?

修改

我不得不拿出一个解决方案,VB.NET

I've had to come up with a VB.NET solution

<script runat="server">
  Private Function GetSecondaryNavItems() As String
    Dim sRet As String = ""

    Dim oCurrNode As System.Web.SiteMapNode = Nothing
    Dim oCurrParentNode As System.Web.SiteMapNode = Nothing

    'Dim sCurrPage As String = GetURL(Request.ServerVariables("SCRIPT_NAME").ToLower())
    Dim sCurrPage As String = GetURL(HttpContext.Current.Request.ServerVariables("SCRIPT_NAME").ToLower())
    oCurrNode = GetCurrentNode(sCurrPage, SiteMap.RootNode)

    If Not oCurrNode Is Nothing Then
      oCurrParentNode = oCurrNode.ParentNode
    End If

    If Not oCurrParentNode Is Nothing Then
      If Not oCurrParentNode Is SiteMap.RootNode Then
        sRet += "Parent Folder Link"

        If Not oCurrNode Is Nothing Then
          For Each oChild As SiteMapNode In oCurrParentNode.ChildNodes
            sRet += "Link for child"
          Next
        End If
      End If
    End If

    Return sRet
  End Function

  Private Function GetURL(ByVal fullURL As String) As String
    Return fullURL.Substring(fullURL.LastIndexOf("/"))
  End Function

  Private Function GetCurrentNode(ByVal _sCurrentPageURL As String, ByVal _oNode As SiteMapNode) As SiteMapNode
    Dim oNodeRet As SiteMapNode = Nothing

    For Each oNodeCheck As SiteMapNode In _oNode.ChildNodes
      If oNodeCheck.HasChildNodes = True Then
        oNodeRet = GetCurrentNode(_sCurrentPageURL, oNodeCheck)
      End If

      If oNodeRet Is Nothing Then
        Exit For
      End If

      Dim sURL As String = oNodeCheck.Url.ToLower()
      Dim iPos As Integer = sURL.IndexOf("?")

      If iPos > 0 Then
        sURL = sURL.Substring(0, iPos)
      End If

      iPos = sURL.LastIndexOf("/")

      If iPos > 0 Then
        sURL = sURL.Substring(iPos)
      End If

      If sURL = _sCurrentPageURL Then
        oNodeRet = oNodeCheck
        Exit For
      End If
    Next

    Return oNodeRet
  End Function
</script>

这是在母版页文件直接(临时,我将它放在模型背后的code版本)。

This is in the master page file directly (temporary, I'll place it in the code behind model later).

我则在身体得到这个

<div id="sidebar">
  <%= GetSecondaryNavItems() %>
</div>

再次暂时只是为了测试。它实际上并不输出任何东西,但随后我在想我的GetURL定义不正确。我是假设它是刚刚起步的实际文件?我可能是非常错误的,虽然:)

Again, temporarily just to test. It doesn't actually output anything but then I'm thinking my GetURL definition is incorrect. I was assuming it was just getting the actual file? I could be very wrong though :)

编辑编辑:出于某种原因,我没有得到任何输出,所以我认为这是我的地图。我需要调试它,但我此刻的远程处理的所以它是很慢;)

EDIT EDIT: For some reason I'm not getting any output, so I thought it was my sitemap. I'll need to debug it but I'm remoting in at the moment so it's quite slow ;)

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode url="Accounts/Default.aspx" title="Accounts"  description="Accounts">
    <siteMapNode url="Accounts/Test.aspx" title="Client Balances" description="Client Balances">
      <siteMapNode url="Hello.aspx" title="Hello"  description="rarar" />
      <siteMapNode url="Hiya.aspx" title="Hiya"  description="rarar" />
    </siteMapNode>
    <siteMapNode url="Test.aspx" title="Test"  description="rarar" />
  </siteMapNode>
</siteMap>

下面的例子地图。

推荐答案

您仍然可以使用Sitemap.sitemap文件来控制导航,但你不会使用任何内置控件在asp.net实现这个。我只是做了差不多这事上我刚刚完成一个网站。

You could still use the Sitemap.sitemap file to control your navigation, but you wouldn't use any of the built-in controls in asp.net to achieve this. I just did almost this very thing on a site I just finished.

请您所有的网页从基页类继承(或使用母版页,无论哪种方式,你只有你的code复印件1份)。

Make all of your pages inherit from a base page class (or use master pages, either way you'll only have 1 copy of your code.)

创建每个页面上的一个div或者跨度,适当命名的东西(divNav或spnNav或其他)。

Create a div or span on each page, named something appropriate (divNav or spnNav or whatever).

在你的基地页面,在页面加载,通过所有的站点地图结点循环查找当前页面的节点。这需要一个递归调用

In your base page, on page load, loop through all the sitemap nodes to find the current page's node. This needs to be a recursive call.

	// Pass the current page url, all the way through the .aspx.  In other words, do NOT pass any kind of 
	// query string.
	private SiteMapNode GetCurrentNode(string _sCurrentPageURL, SiteMapNode _oNode)
	{
	    SiteMapNode oNodeRet = null;

	    foreach (SiteMapNode oNodeCheck in _oNode.ChildNodes)
	    {
	        if (oNodeCheck.HasChildNodes == true)
	        {
	            oNodeRet = GetCurrentNode(_sCurrentPageURL, oNodeCheck);
	        }

	        if (oNodeRet != null)
	            break;

	        string sUrl = oNodeCheck.Url.ToLower();
	        int iPos = sUrl.IndexOf("?");
	        if (iPos > 0)
	            sUrl = sUrl.Substring(0, iPos);
	        iPos = sUrl.LastIndexOf("/");
	        if (iPos > 0)
	            sUrl = sUrl.Substring(iPos);

	        if (sUrl == _sCurrentPageURL)
	        {
	            oNodeRet = oNodeCheck;
	            break;
	        }
	    }
	    return oNodeRet;
	}

一旦你的当前节点,获得其母公司。

Once you have the current node, get its parent.

添加一个链接(即菜单回来了一个文件夹作为你称它)。

Add a link (the "up menu to come back out a folder" as you called it).

然后做一个foreach(在的SiteMapNode parent.ChildNodes)

Then do a foreach(SiteMapNode in parent.ChildNodes)

添加一个链接,每个孩子。

Add a link for each of the children.

所以,我们主要的电话,我们呼吁每一个页面加载,是这样的:

So, our main call, that we called on every page load, was like this:

	public string GetSecondaryNavItems()
	{
	    string sRet = "";

	    // Get the node that matches most of this url...
	    System.Web.SiteMapNode oCurrNode = null;
	    System.Web.SiteMapNode oCurrParentNode = null;

	    string sCurrPage = GetURL(Request.ServerVariables["SCRIPT_NAME"].ToLower());

	    oCurrNode = GetCurrentNode(sCurrPage, SiteMap.RootNode);

	    if(oCurrNode != null)
	        oCurrParentNode = oCurrNode.ParentNode;

	    if(oCurrParentNode != null)
	    	  if(oCurrParentNode != SiteMap.RootNode)
	    		  sRet += "Parent Folder link";

			if(oCurrNode != null)
			{
	        foreach (System.Web.SiteMapNode oChild in oCurrParentNode.ChildNodes)
	        {
	    		    sRet += "Link for child";
	    	  }
	    }
	}

我要告诉你,上面的code是部分复制和我豪爽的一部分。但是,这应该给你一个良好的开端,我想。

I have to tell you that the code above is part copied and part freehanded by me. But this should give you a good start, I would think.

编辑:所以,对不起!下面是使用getURL处理...

So sorry! Here is the GetURL proc...

    public string GetURL(string _sURL)
    {
        string sRet = _sURL;

        int iPos = sRet.IndexOf("?");
        if (iPos > 0)
            sRet = sRet.Substring(0, iPos);
        iPos = sRet.LastIndexOf("/");
        if (iPos > 0)
            sRet = sRet.Substring(iPos);

        return sRet;
    }

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

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