如何将默认调试路径路由到 asp.net mvc 中的实际路径?
当我在 vs2008 上单击“运行”来尝试一个页面时,它会尝试加载
http://localhost:14092/Views/Employee/Index.aspx
,它应该是
http://localhost: 14092/Employee/Index
或 http://localhost:14092/
如何添加这 2 条路由? (我想知道如何做到这两点,以便我可以根据需要交换它们。
这是我当前的路由代码:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
When I click run on my vs2008 to try out a page it tries to load
http://localhost:14092/Views/Employee/Index.aspx
which should be
http://localhost:14092/Employee/Index
or http://localhost:14092/
How do I add these 2 routes? (I want to know how to do both so I can swap them as desired.
Here's my current routing code:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否已将调试选项更改为始终从特定页面开始?如果没有,请转到项目的属性并更改调试属性,以使调试器始终在根页面启动项目。我通常还会告诉它始终使用相同的端口 - 这样我就可以使用 FF 或 IE,历史记录会为我提供正确的 URL。请参阅 Steven Walther 的文章 如何运行 ASP.NET MVC 应用程序作为替代方案。
Have you changed the debugging options to always start at a specific page? If not, go to your project's properties and change the debugging properties to have your debugger to always start the project at the root page. I typically also tell it to always use the same port -- so that I can use FF or IE and the history works to give me the right URL. See Steven Walther's article on how to run an ASP.NET MVC application for alternatives.