[英]How to use URL Rewrite in ASP.Net
我正在尝试使用简单的URL重写。
我正在尝试将页面加载时的URL缩短为简化版本(无文件扩展名)。 我的网址中没有使用任何查询字符串。
这是当前的网址:
http://localhost:64341/Report/MainPage.aspx
页面加载后,我希望看到以下内容:
http://localhost:64341/Report/MainPage
这是我在Global.asax文件中拥有的代码:
protected void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routeCollection)
{
routeCollection.MapPageRoute("RouteForCustomer", " MainPage", "~/ MainPage.aspx");
}
页面加载后,如何在后面的代码中实现此目的?
试试Context.RewritePath("http://localhost:64341/Report/MainPage", true);
检查此博客http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.