mydomain/product到mydomain/products/product的mappageroute [英] mappageroute for mydomain/product to mydomain/products/product

查看:54
本文介绍了mydomain/product到mydomain/products/product的mappageroute的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我在表单的任何产品页面上都收到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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆