使用 ASP.NET MVC2,IIS 6 不转发空路由

发布于 2024-10-04 02:25:01 字数 940 浏览 7 评论 0原文

首先让我解释一下,我使用的是托管解决方案,在 IIS 6 的配置和设置方面我无能为力。

我在一定程度上使用了 MVC2,我正在使用以下 Global.asax 代码

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default",
            "{controller}.aspx/{action}/{id}",
            new { action = "Index", id = "" }
        );

        routes.MapRoute(
            "Root",
            "",
            new { controller = "Default", action = "Index", id = "" }
        );
    }

:第一条路线,我必须指定 {controller}.aspx,因为 IIS 6 无法执行非 aspx 代码(或类似的代码,不太确定)。

没关系,以下内容有效: hxxp://mysite.com/home.aspx、hxxp://mysite.com/projects.aspx、hxxp://mysite.com/contact.aspx

都是控制器,我也可以运行它们受尊重的操作。

问题是我无法正确执行空 URL(即 hxxp://mysite.com/),它给我一个“目录列表被拒绝”错误。

我的问题是,对于位于根目录的 default.aspx 文件(确实执行),我可以在不使用简单的 Response.Redirect 的情况下加载 Home 控制器吗?

谢谢你, 马修

First let me explain that I am on a hosted solution, and there is not much I can do in ways of configuration and settings for IIS 6.

I have MVC2 working to a degree, I'm using the following Global.asax code:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default",
            "{controller}.aspx/{action}/{id}",
            new { action = "Index", id = "" }
        );

        routes.MapRoute(
            "Root",
            "",
            new { controller = "Default", action = "Index", id = "" }
        );
    }

In the first route, I had to specify {controller}.aspx, due to IIS 6 not being able to execute non aspx code (or something like that, not really sure).

Which is fine, the following works:
hxxp://mysite.com/home.aspx, hxxp://mysite.com/projects.aspx, hxxp://mysite.com/contact.aspx

which are all controllers and I can run their respected actions as well.

The problem is that I can not do an empty URL properly (ie hxxp://mysite.com/), it gives me a "Directory Listing Denied" error.

The question I have, is with a default.aspx file located at root (which does execute), can I load the Home controller WITHOUT using a simple Response.Redirect?

Thank you,
Matthew

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最单纯的乌龟 2024-10-11 02:25:01

事实上,您收到“目录列表被拒绝”意味着 isapi filetr 与 MVC 不匹配。

The fact that you are getting "Directory Listing Denied" means that the isapi filetr don't match for working with MVC.

你穿错了嫁妆 2024-10-11 02:25:01

事实上,您收到“目录列表被拒绝”意味着您没有默认文档,因此服务器正在尝试显示根文件夹上的文件列表。

将默认文档更新为“Default.aspx”之类的内容。您的托管提供商应该有一个选项。这很常见。

The fact that you are getting "Directory Listing Denied" means that you don't have a default document and therefore the server is trying to show a list of files on the root folder.

Update the Default Document to something like "Default.aspx". Your hosting provider should have an option for this. This is very common.

月下凄凉 2024-10-11 02:25:01

您可以在 IIS6 和 IIS7 上禁用此行为

// Disable IIS looking at physical files and directories
RouteTable.Routes.RouteExistingFiles = true;

You can disable this behaviour on IIS6 and IIS7

// Disable IIS looking at physical files and directories
RouteTable.Routes.RouteExistingFiles = true;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文