在子域中运行 ASP.NET MVC 会使 Html.ActionLink 呈现损坏的链接
我正在子域中运行 MVC
http://test.domain.com 指向我的 webhost4life 帐户上的 /Test 目录。
Html.ActionLink("About", "About", "Home")
它呈现一个链接到
http://test.domain.com/Test/Home/About -- 给出 404
链接应该是 ..
http://test.domain.com/ Home/About
有没有办法覆盖 ActionLink 以省略渲染时的 /Test ?
谢谢
实验1
我添加了一条到表的路由,如下所示...
routes.MapRoute(
"Test", // Route name
"Test/{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
现在操作链接呈现如下链接.. http://test.domain.com/Test/Test/Home/About/< /a> 单击此按钮时,它不会给出 404,但会给出Home控制器About操作。
结果
不再有损坏的链接,但网站呈现丑陋的网址。
I am running MVC in a subdomain
http://test.domain.com which points to the /Test directory on my webhost4life account.
Html.ActionLink("About", "About", "Home")
it renders a link to
http://test.domain.com/Test/Home/About -- which gives a 404
the link should be ..
http://test.domain.com/Home/About
is there a way to override ActionLink to omit the /Test on render?
Thank you
Experiment 1
I added a route to the table like this...
routes.MapRoute(
"Test", // Route name
"Test/{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
and now action link renders links like this..
http://test.domain.com/Test/Test/Home/About/
when this is clicked it does not give a 404 but gives the Home controler About action.
Result
No more broken links but the site renders ugly urls.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于使用大量子域的站点,我使用 ITCloud 的一个漂亮的 MVC 扩展,称为 UrlRouteAttribute。它允许您将路由分配给每个操作作为设置路径和名称的属性。我已扩展它以允许完全限定的路径 - 因此包括控制器应附加到的域/子域。如果您对此感兴趣,我会在某个地方上传一份副本。
For a site using lots of subdomains I use a nifty MVC extension from ITCloud called UrlRouteAttribute. It allows you to assign a route to every action as an attribute setting the path and name. I have extended this to allow fully qualified paths - so to include the domain/subdomain the controller should attach to. If this is something you'd be interested in I'll upload a copy somewhere.