ASP.NET MVC 路由在虚拟目录中不起作用
我有一个 asp.net mvc 2 应用程序(使用 .net 4.0),在虚拟目录中托管时无法正确路由。我有以下简单的路由规则:
routes.MapRoute(
"Default", // Route name
"{action}", // URL with parameters
new { controller = "accounts" } // Parameter defaults
);
我正在尝试解析 http://mydomain.com/accounts/new< /a>.其中“accounts”是虚拟目录。如果我将应用程序放在 IIS 网站的根目录中,它可以很好地路由 http://mydomain.com/new,但如果我将应用程序放在虚拟目录中,则会收到 404 错误。我已经调试过,它正在执行 global.asax 并在 vdir 中配置路由。对于虚拟目录中的路由,我需要做一些特殊的事情吗?
供参考。我使用的是 vdir,因为根目录中有 wordpress。
谢谢!
另一件事是,如果我在参数默认值中指定默认操作,它将执行默认操作/控制器,但它永远不会匹配其他任何内容。
I have an asp.net mvc 2 app (using .net 4.0) that isn't routing correctly when hosted in a virtual directory. I have the following simple routing rule:
routes.MapRoute(
"Default", // Route name
"{action}", // URL with parameters
new { controller = "accounts" } // Parameter defaults
);
I'm trying to resolve http://mydomain.com/accounts/new. Where "accounts" is a virtual directory. If I put the app in the root of an IIS website it routes fine for http://mydomain.com/new, but if I put the app in a virtual directory I get 404 errors. I've debugged and it is executing global.asax and configuring routing when in the vdir. Is there something special I need to do for routing in a virtual directory?
FYI. I'm using a vdir because the root has wordpress in it.
Thanks!
one more thing is that if I specify a default action in parameter defaults, it will execute the default action/controller, but it never matches anything else.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想通了。 Wordpress(我安装在网站根目录下)配置了一些 URL 重写规则,这些规则阻止 asp.net mvc 接收除虚拟目录根目录之外的任何请求。任何超出此路径的内容都会被重写到index.php,这当然在我的mvc应用程序中不存在。
我删除了重写规则,现在一切都按预期进行。
I figured it out. Wordpress (which I had installed at the website root) had configured some URL rewrite rules which were preventing asp.net mvc receiving any requests other than the virtual directory root. Anything with a path beyond that was being rewritten to index.php which of course didn't exist in my mvc app.
I removed the rewrite rule, and now everything works as expected.
如果你把它改成:
does it work if you change it to: