【问题标题】:Adding MVC Application under another MVC application in IIS在 IIS 中的另一个 MVC 应用程序下添加 MVC 应用程序
【发布时间】:2019-09-27 11:26:52
【问题描述】:

我有两个独立的 MVC 应用程序,我想将其中一个部署在另一个之下。我在 ISS 中创建了一个网站和一个应用程序,例如“testsite1”和“testsite2”。 local.testsite1 运行良好,但 local.testsite1/testsite2 无法正常运行,因为 testsite1 正在捕获请求并尝试查找控制器并引发异常。我不想在 IIS 中创建两个不同的网站。我该如何解决这个问题?

【问题讨论】:

    标签: asp.net asp.net-mvc asp.net-mvc-4 iis


    【解决方案1】:

    local.testsite1local.testsite1/testsite2 是同一个域。不是子域。这意味着寻找控制器的应用程序/IIS 是正确的行为。

    您可以考虑将站点合并为一个并使用 MVC 区域将它们分开吗?此外,如果您不合并站点,您将如何分别为站点触发 app_start 和其他事件?

    在这种情况下,您可以编写自定义路由,将 testsite2 的路由与 testsite1 的路由分开。

    例如 testsite1 的路由定义可以是:

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
        namespaces: new string[] { "YourApp.Controllers" }
    );
    

    而你的testsite2区域路由注册可以是:

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Admin_default",
            "Admin/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional },
            new { controller = "Branch|AdminHome|User" },
            new[] { "YourApp.Areas.testsite2.Controllers" }
        );
    }
    

    更多关于实现的信息在这里:Mvc area routing?

    【讨论】:

      【解决方案2】:

      您可以尝试将第二个网站设置为 IIS 中测试站点 1 中的应用程序。

      为此,请在 IIS 中右键单击第一个 MVC 应用程序的网站,单击 Add Application...,设置别名、要使用的池以及第二个 MVC 应用程序文件的路径。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多