標籤:c tar ext a 檔案 使用
一、前後台代碼:
Global.cs:
using System.Web.Routing;
。。。
void Application_Start(object sender, EventArgs e)
{
// 在應用程式啟動時啟動並執行代碼
//RegisterRoutes();
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("ProductsRoute", "Products/list-{lbid}", "~/Products/ProList.aspx");
routes.MapPageRoute("ProductsDetail", "Products/show-{id}.html", "~/Products/Show.aspx");
}
Default.aspx添加連結:
<p>
<ul>
<li><a href="#">產品中心</a></li>
<li>·<a href="Products/list-1">產品分類1</a></li>
<li>·<a href="Products/list-2">產品分類2</a></li>
</ul>
</p>
<p>
<ul>
<li><a href="Products/show-1.html">產品1</a></li>
<li>·<a href="Products/show-2.html">產品2</a></li>
<li>·<a href="Products/show-3.html">產品3</a></li>
</ul>
</p>
ProList.aspx.cs 中接收路由參數:
protected void Page_Load(object sender, EventArgs e)
{
string lbid = Page.RouteData.Values["lbid"] as string;//接收路由參數
lblLbid.Text = "lbid="+lbid;
//下面寫商務邏輯
}
Products/Show.aspx 接收路由參數:
protected void Page_Load(object sender, EventArgs e)
{
lblMsg.Text = "id=" + Page.RouteData.Values["id"] as string;//接收路由參數;
}
效果
二、IIS部署
如果訪問html時出現 404 錯誤,有以下兩種解決方案:
1. 在IIS7.0中,需要把網站應用程式程式池中的託管管道模式設定為:整合。否則會提示 404 錯誤。
?
2. 如果實際條件不允許設定為整合模式,則需要添加“處理應用程式對應”,需添加.html檔案,使用asp.net api 處理。