c# - MVC 路由不适用于虚拟目录上的非默认/根操作 Controller

标签 c# asp.net asp.net-mvc-2

我在 IIS 上使用默认的“ASP.NET MVC 2 Web 应用程序”(我没有管理员访问权限)并且我可以导航到

“服务器/ITEC”

如果服务器不返回错误 - 404 错误,我无法导航到“server/ITEC/About”。

我还使用 RouteDebugger 进行测试 - 当我使用默认的“server/ITEC”时它匹配(也就是默认的 home/index Controller 操作)但是当我手动输入“server/ITEC/About”时我不甚至看不到 RouteDebugger 页面。另外,值得注意的是,当我在“server/Itec/About”中放置一个“index.html”文件时,它会返回结果,这让我相信该目录被配置为在处理请求时使用文件系统而不是 MVC 路由- 这是一个安全的假设吗?

如何更新我的 Global.asax 文件以便我可以返回非默认 Controller /操作?或者这是服务器问题,我该如何解决?

谢谢!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace mikeProg
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode,
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        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 = UrlParameter.Optional } // Parameter defaults            
            );

            RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
        }
    }
}

最佳答案

我想通了!

在 aspnet_isapi.dll 的 Wildcard application maps 部分,复选框

“验证文件存在”已被选中。

一旦我要求系统管理员取消选中它,一切都会完美地路由。

为什么这甚至是一个选项???我什么时候使用它?

关于c# - MVC 路由不适用于虚拟目录上的非默认/根操作 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14968979/

相关文章:

C#,我可以在读取 SQL Server 表时插入和删除它吗

asp.net - 如何使用 elmah 记录警告

c# - PayU 集成网络服务 URL

c# - 在 asp.net C# 中的客户端打印机上打印 pdf 文件?

c# - ASP.NET MVC 2 UpdateModel() 不更新内存或数据库中的值

c# - DTO 和服务之间的调用

c# - 客户端/服务器应用程序 - 丢失字节

asp.net-mvc - 带有连字符的 ActionLink htmlAttributes

c# - 将模型属性表达式传递给 View

c# - ASP.Net 使用重定向创建服务器端发布到外部网站