大家好,我看过很多文章,url rewriting
但我没有找到任何符合我要求的文章。假设我有两个页面Default.aspx
,并且Default1.aspx
..在初始加载时,我想将我的Default.aspx
内容重写为类似的urlrewrite\dummy.aspx
内容,并且在Default.aspx
我单击此按钮时,我将有一个按钮,我将重定向到Default1.aspx
我想将其重写为urlrewrite\dummy1.aspx
我只是发布示例重写,但如果有更好的重定向方法,请帮助我..
如果我有一些20-50
页面,那么重写所有页面的最佳方法是什么
我的 global.asax 文件
<%@ Application Language="C#" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Routing" %>
<script RunAt="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RegisterRoutes(System.Web.Routing.RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routeCollection)
{
string root = Server.MapPath("~");
System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(root);
System.IO.FileInfo[] files = info.GetFiles("*.aspx", System.IO.SearchOption.AllDirectories);
foreach (System.IO.FileInfo fi in files)
{
string pageName = fi.FullName.Replace(root, "~/").Replace("\\", "/");
routeCollection.MapPageRoute(fi.Name + "Route", fi.Name, pageName);
}
routeCollection.MapPageRoute("DummyRouteName1", "Dummy", "~/Default2.aspx");
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
</script>