mappageroute for mydomain/product to mydomain/products/product

风格不统一 提交于 2019-12-25 14:39:47

问题


At the moment Im getting a 404 error for any product page of the form mydomain/product

I would like to map these to mydomain/showproduct.aspx?pagename=product

Is it something like routes.MapPageRoute( "Product",
"{Prodname}",
"~/showproduct.aspx"
); Not sure if this will work and not sure about the querystring


回答1:


That URL you would like to map looks more like a classic ASP.NET URL then an MVC URL. In MVC you are not linking to physical files but action methods in a controller class.

In MVC it should look more like: mydomain/products/show/productname

The default URL route should handle the above URL structure:

            routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

EDIT:

If you have to do it the other way try something like this:

    routes.MapRoute(
   "Page",
   "{name}.aspx",
   new { controller = "Page", action = "Index", id = "" }
);


来源:https://stackoverflow.com/questions/5302071/mappageroute-for-mydomain-product-to-mydomain-products-product

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!