ASP.NET MVC路由的虚拟目录不工作 [英] ASP.NET MVC Routing not Working in Virtual Directory

查看:1091
本文介绍了ASP.NET MVC路由的虚拟目录不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net MVC 2的应用程序(使用.NET 4.0)在虚拟目录托管时不正确的路由。我有以下简单的路由规则:

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
        );

我试图解决 http://mydomain.com/accounts/new 。其中,账户是一个虚拟目录。如果我把应用程序在一个IIS网站它的路线罚款 http://mydomain.com/new 的根,但如果我把应用程序在虚拟目录中,我得到404错误。我已经调试和正在执行的Global.asax,并在VDIR时配置路由。是不是有什么特别的,我需要在一个虚拟目录路由办?

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?

仅供参考。我使用的是VDIR因为根中有字preSS。

FYI. I'm using a vdir because the root has wordpress in it.

谢谢!

一件事是,如果我指定参数默认默认操作,它会执行默认操作/控制器,但它永远不会匹配任何东西。

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.

推荐答案

我想通了。字preSS(我在网站根目录已经安装),配置了其为preventing asp.net mvc的接收比虚拟根目录外的任何请求某些URL重写规则。有超过一个路径任何正在重写,这当然没有在我的MVC应用程序存在的index.php。

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.

这篇关于ASP.NET MVC路由的虚拟目录不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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