[英]How to use URL Rewrite in ASP.Net
I am trying to use a simple URL rewrite. 我正在尝试使用简单的URL重写。
I am trying shorten the URL on page load to its simplified version (no file extension). 我正在尝试将页面加载时的URL缩短为简化版本(无文件扩展名)。 I am not using any query string in my URL.
我的网址中没有使用任何查询字符串。
Here is the current URL: 这是当前的网址:
http://localhost:64341/Report/MainPage.aspx
When the page loads, I want to see this: 页面加载后,我希望看到以下内容:
http://localhost:64341/Report/MainPage
Here is the code that I have in my Global.asax file: 这是我在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");
}
How can I achieve this in the code behind when the page loads? 页面加载后,如何在后面的代码中实现此目的?
Try Context.RewritePath("http://localhost:64341/Report/MainPage", true);
试试
Context.RewritePath("http://localhost:64341/Report/MainPage", true);
Check this blog http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx 检查此博客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.