想实现这种链接:
www.xxxx.com/news/1015.html
用这两种方法,都实现不了
Html.ActionLink()
Url.Action()
这两种方法,都会生成
/?id=1015
所以只能手动拼接链接地址了,但手动拼接的话,不能指定
new {area="xxx"}
不能指定导致,网站的路由乱了
比如,正常下请求:
www.xxxx.com/news/1015.html 正确
login.xxxx.com/news/1015.html 也能正确请求,
以下是三个路由:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
},
namespaces: new string[] { "NoahHotel.Extensions.Controllers.WebSite" }
);
routes.Add("NoahHotel__Domain_Login", new DomainRoute(
"login.noahhotel.cn",
"{controller}/{action}/{id}",
new
{
area = "Login",
controller = "Home",
action = "Login",
id = UrlParameter.Optional,
Namespaces = new string[] { "NoahHotel.Extensions.Controllers.Login" }
}
));
context.MapRoute(
"Category",
"Category/{Action}/{CategoryId}.html",
new
{
controller="Category",
action="Info",
CategoryId=@"(\d)+"
},
null,
new string[] { "NoahHotel.Extensions.Controllers.WebSite" }
);
是哪里出问题了吗?
自定义路由写在默认路由上面试试。asp.net mvc 的路由匹配机制是先到显得的