【问题标题】:MVC url routes not working after deployment on IIS在 IIS 上部署后,MVC url 路由不起作用
【发布时间】:2019-05-12 13:21:59
【问题描述】:

我有一个在本地运行良好的 MVC 应用程序,但是当部署在 IIS 上时,所有路由都返回 404 未找到。 在某些情况下,我的浏览器会向我显示布局,但不会为该视图带来数据,而是返回 404。

我将向您展示一种在本地运行良好但在 IIS 中失败的方法。

    [Route("/Customer/CustomerDetails/{id}")]
    public async Task<IActionResult> CustomerDetails(int id)
    {
        ApiResult<eCOM_Backend.Api.Responses.Customer> apiResult = await _customerApiMethods.CustomerDetailsAsync(id);
        eCOM_Backend.Api.Responses.Customer customerFromBackend = null;

        if (!apiResult.HasException)
        {
            customerFromBackend = apiResult.Result;
        }
        else
        {
            return RedirectToAction("Error", "Error", new { reason = apiResult.Exception });
        }

        CustomerViewModel customer = customerFromBackend.ToCustomerViewModel();
        return View(customer);
    }

当我像这样调用此方法时:xxx/Customer/CustomerDetails/123 我找不到页面。

我尝试了很多解决方案(修改了 appsettings.json、web.config 等),但到目前为止都没有奏效。

非常感谢!

【问题讨论】:

    标签: asp.net-mvc iis model-view-controller deployment routes


    【解决方案1】:

    看起来这是 dotnet 核心。确保在将应用发布到 IIS 时提供正确的物理路径。喜欢inetpub\wwwroot\YourAppName。在 IIS 中,右键单击您的 Web 应用>管理网站>高级设置,并确保物理路径以您的应用文件夹结尾,而不是 yourApp\someOtherFolder

    【讨论】:

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