mydomain/product到mydomain/products/product的mappageroute [英] mappageroute for mydomain/product to mydomain/products/product
问题描述
目前,我在表单的任何产品页面上都收到404错误mydomain/产品
At the moment Im getting a 404 error for any product page of the form mydomain/product
我想将它们映射到mydomain/showproduct.aspx?pagename = product
I would like to map these to mydomain/showproduct.aspx?pagename=product
是不是有点像路线.MapPageRoute(产品",
"{Prodname}",
〜/showproduct.aspx"
);不知道这是否行得通,也不确定查询字符串
Is it something like
routes.MapPageRoute(
"Product",
"{Prodname}",
"~/showproduct.aspx"
);
Not sure if this will work and not sure about the querystring
推荐答案
您要映射的URL看起来更像是经典的ASP.NET URL,而不是MVC URL.在MVC中,您不是链接到物理文件,而是链接到控制器类中的操作方法.
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.
在MVC中,其外观应类似于:mydomain/products/show/productname
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
);
如果必须这样做,请尝试如下操作:
If you have to do it the other way try something like this:
routes.MapRoute(
"Page",
"{name}.aspx",
new { controller = "Page", action = "Index", id = "" }
);
这篇关于mydomain/product到mydomain/products/product的mappageroute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!