I am trying to use a simple URL rewrite.
I am trying shorten the URL on page load to its simplified version (no file extension). 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:
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);
Check this blog http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.