木子屋 Dnawo's BLOG

System.Web.HttpException: 无法使用前导 .. 在顶级目录上退出。

👤 dnawo 📅 2010-06-02 👁 8857 👍 0 💬 0 🔄 来源:本站原创
在ASP.NET页面使用TreeView控件时意外的报错,异常详细信息:

System.Web.HttpException: 无法使用前导 .. 在顶级目录上退出。

问题重现

Web.sitemap:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode url="/" title="木子屋"  description="">
    <siteMapNode url="../Default.aspx" title="首页"  description="" />
    <siteMapNode url="List1.aspx" title="分类一"  description="">
      <siteMapNode url="Article11.aspx" title="文章一"  description="" />
      <siteMapNode url="Article12.aspx" title="文章二"  description="" />
    </siteMapNode>
    <siteMapNode url="List2.aspx" title="分类二"  description="">
      <siteMapNode url="Article21.aspx" title="文章一"  description="" />
      <siteMapNode url="Article22.aspx" title="文章二"  description="" />
    </siteMapNode>
    <siteMapNode url="List3.aspx" title="分类三"  description="">
      <siteMapNode url="Article31.aspx" title="文章一"  description="" />
      <siteMapNode url="Article32.aspx" title="文章二"  description="" />
    </siteMapNode>
  </siteMapNode>
</siteMap>

Default.aspx:
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>TreeView控件示例-Mzwu.Com</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
        <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" 
            ExpandDepth="1" ShowLines="True">
        </asp:TreeView>
    
    </div>
    </form>
</body>
</html>

错误分析

Web.sitemap文件中的url相对地址,在TreeView控件中都将站点根目录(顶级目录)视为起始路径,而不论TreeView控件所在页面的实际位置,所以对于"../Default.aspx"这样的url,已跳出了站点目录之外,程序并报错。

评论(0)

暂无评论。

验证码
评论需审核通过后显示
← 上一篇 css让页面制作更简单 下一篇 → 软件也有重量?