【发布时间】:2010-11-14 18:13:18
【问题描述】:
我正在建立一个网上商店,但有些网址有点问题。
我的数据库中有一个很大的部门和类别目录,我用它来形成我的主菜单。
URL 的格式为 Application/Store/Department/Category (所有商店 URL 都被重写为 store.aspx?Querystringstuff)
问题是我的代码生成的一些 url 可以正常工作,但会阻止页面的 CSS 正确加载。
特别是源文本包含斜杠的 URL。 我当然是对源文本进行 URL 编码,但我仍然遇到问题。
我的 css 链接在母版页中-
<link rel="stylesheet" type="text/css" href="~/CSS/Layout.css" runat="server">
有效的示例链接 -
制冰机
http://localhost:1079/ABCWeb/Store/Refrigeration+Equipment/Ice+Machines.aspx
蒸盘
http://localhost:1079/ABCWeb/Store/Catering+%26+Buffet/Steam+Table+Pans.aspx
示例链接-
餐巾架/分配器
http://localhost:1079/ABCWeb/Store/Tabletop/Napkin+Holders%2fDispensers.aspx
蝾螈/奶酪熔炉
http://localhost:1079/ABCWeb/Store/Cooking+Equipment/Salamanders%2fCheesemelters.aspx
如果重要的话,这里是我构建 URL 的代码- 该数组包含路径中的项目数组 第一个元素未编码,因为它包含当前存储路径。
private static System.Text.StringBuilder AppendAnchor(this System.Text.StringBuilder str, string[] path)
{
return str.Append("<a href='")
.Append(path.Aggregate((a, b) => a + "/" + HttpUtility.UrlEncode(b)))
.Append(".aspx'><span>")
.Append(HttpUtility.HtmlEncode(path[path.Length-1]))
.Append("</span></a>");
}
感谢您的帮助!
【问题讨论】:
标签: c# asp.net url-rewriting