[英]URL Rewriting in Asp.net MVC 3
我是Asp.net MVC的新手。 我正在創建Web應用程序,在這里我必須用產品名稱重寫url。 我不確定在MVC中是否可行。
就像http://sitename.com/category1/product1
http://sitename.com/category1/product2
將具有相同的頁面。
有一些工具可以在MVC中生成友好的url。
請查看以下文章-http: //www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/asp-net-mvc-routing-overview-cs-有關如何處理此問題的概述在MVC中。
本質上,您需要在應用程序啟動時配置路由,如下所示。 通常可以在global.asax
文件中完成此操作,但可以按區域等進行拆分。
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes); // Reigster the routes
}
這是默認路由,但是您可以根據需要進行定義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.