[英]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.