1
我只想問是否有使用masterpage的URL路由的解決方法。我把鏈接放在我的主頁面(即第一個鏈接是href =「Bookstore/CSS」,另一個鏈接是href =「tools/toolx」)如果我點擊第一個鏈接,它會將我重定向到正確的url, :2039/Bookstore /但是如果我點擊下一個鏈接,它會將我重定向到localhost:2039/tools/Bookstore/CSS,但鏈接應該是localhost:2039/Bookstore/CSS。ASP.NET 4.0 webforms在主頁面內路由
下面是代碼
Global.asax的
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RouteTable.Routes.MapPageRoute("StoreRoute",
"BookStore/{Name}",
"~/Webpages/BookStore/ViewBookDemo.aspx");
RouteTable.Routes.MapPageRoute("mytool",
"tools/{Name}",
"~/tools/tools.aspx");
}
母版源代碼
<div class="page">
<div >
<div class="title">
<h1>
URL Routing in MAsterpage
</h1>
</div>
<div class="clear hideSkiplink">
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
</Items>
</asp:Menu>
</div>
</div>
<div class="clear"> </div>
<div style=" width:90%">
<div style="float:left; width:25%;border: 1px solid #009933;">
<br />
<a href="Bookstore/CSS">Click Here to go to bookstore</a>.
<div class="clear"> </div>
<p>
<a href="tools/toolx">Click Here to go to tools</a>.
</p> </div>
<div style="float:right;width:73%">
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</div>
</div>
</div>
</div>
<div class="clear"> </div>
<div class="footer">
</div>