Routing. What should I put in HREF?
I have implemented routing feature into my ASP.NET web application and would like to hide .aspx extension from url. Wrote code below and it works fine for my need, the question would be what URL should I put in my HREF now? For example I have menu buttons about.aspx, profile.aspx and etc. Should I remove aspx extension from links in HREF?
static void RegisterRoute(RouteCollection routes)
{
routes.Ignore("{resource}.axd/{*pathInfo}");
routes.Ignore("favicon.ico");
routes.MapPageRoute("All", "{filename}", "~/{filename}.aspx")开发者_如何学JAVA;
}
void Application_Start(object sender, EventArgs e)
{
RegisterRoute(RouteTable.Routes);
}
Yes you can remove the .aspx from those URL, and add any other extension you want. Better you add extension whatever you like. If you don't add the extension then also it will work but create problem in some cases such as if you request the image from images folder and also you have the page called images.aspx. This is just an example, you have to keep in mind such problems if you are not adding extensions. So better you should add the extension like .html or .do or whatever you like.
Thanks
You should use the name of your route if that's what you want users and robots to see.
精彩评论