地址伪静态化 动态地址转换为静态地址

时间仓促,简单整理些。

1、Global.asax文件增加命名空间:

using System.Web.Routing;

同时需有以下方法:

void Application_Start(object sender, EventArgs e)

{

// 在应用程序启动时运行的代码

RegisterRoutes(RouteTable.Routes);

}

/// <summary>

/// 注册跳转路由

/// </summary>

/// <param name="routeCollection"></param>

private void RegisterRoutes(RouteCollection routeCollection)

{

//RouteValueDictionary parameters = new RouteValueDictionary { {"ParentClassID",54},{"ClassID",55},{"MattersType",0}};

// routeCollection.MapPageRoute("LoadComplox", "ComploxItems/LoadComplox_{ParentClassID}_{ClassID}_{MattersType}.html", "~/ComploxItems/LoadComplox.aspx", true, parameters);

routeCollection.MapPageRoute("ComploxDetail", "ComploxItems/ComploxDetail_{MattersType}_{index}_{ParentClassID}_{ClassID}_{MatterID}_{ElementTypeID}.html", "~/ComploxItems/ComploxDetail.aspx");


routeCollection.MapPageRoute("WeiboIndex", "WeiboIndex_{id}.html", "~/WeiboIndex.aspx");

routeCollection.MapPageRoute("WeiboTag", "WeiboTag_{tag}.html", "~/WeiboTag.aspx");


}

相应方法的使用可百度更详细内容。

2、获取url的参数,Page.RouteData.Values["id"]

兼容2种获取参数方式

if (Page.RouteData.Values["id"] != null)

{

id = Page.RouteData.Values["id"].ToString();

}

else

{

id = Request["id"];

}




你可能感兴趣的:(伪静态,静态页面,动态页面)