How to remove .aspx extension from url
2 answers
If you are using web forms you need to add a custom router handler using URL Routing in the file Global.asax
. Check out this sample:
Global.asax
public class Global : System.Web.HttpApplication
{
//Register your routes, match a custom URL with an .aspx file.
private void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("About", "about", "~/about.aspx");
routes.MapPageRoute("Index", "index", "~/index.aspx");
}
//Init your new route table inside the App_Start event.
protected void Application_Start(object sender, EventArgs e)
{
this.RegisterRoutes(RouteTable.Routes);
}
}
+4
source to share
You need to complete URL Rewriting
URL rewriting is the process of intercepting an incoming web request and redirecting the request to another resource. When doing URL Rewriting, typically the requested URL is checked and based on its value, the request is redirected to another URL.
You can add this to Web.Config
<urlMappings enabled="true">
<add url="~/questions/ask" mappedUrl="~/questions/ask.aspx?page=Ask"/>
</urlMappings>
+2
source to share