簡體   English   中英

具有自定義URL的MVC路由ASP.NET

[英]MVC Route ASP.NET that had custom URL

我以前的asp.net頁面有這種網址

本地主機/產品/產品名稱/Item123.aspx

產品ID為123,我將獲得該ID,然后將其傳遞給路由引擎以從數據庫中獲取正確的數據,然后顯示該頁面。

本地主機/產品/產品名稱/項目456.aspx

將獲得產品ID 456。

我正在用MVC重寫網站,我想知道是否有人可以告訴我如何進行路由以使其向后兼容以及localhost / Product / This-Is-The-Name-Of-The-Product / Item123 .aspx將轉到localhost / Product / 123

我正在使用MVC 5 BTW。

U可以同時使用2條路線:

routes.MapRoute( //for localhost/Product/This-Is-The-Name-Of-The-Product/Item456.aspx
            name: "",
            url: "Product/{ProductName}/item{id}.aspx",
            defaults: new { controller = "Product", action = "Index", id= UrlParameter.Optional }
        );

        routes.MapRoute( //this url for localhost/Product/123
            name: "",
            url: "Product/{id}",
            defaults: new { controller = "Product", action = "Index", id = UrlParameter.Optional }
        );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM