我正在尝试使用简单的 URL 重写。
我正在尝试将页面加载时的 URL 缩短为其简化版本(无文件扩展名)。我没有在我的 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
关于c# - 如何在 ASP.Net 中使用 URL 重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14628701/