我有一个使用 .NET Framework 4.7.1 的应用程序,其中定义了 WebAPI 和 MVC 路由。它们都在使用 IISExpress 进行本地调试时工作,但是当我部署到开发服务器(带有 IIS 8.5 的 Windows Server 2012R2)时,我得到的只是每个路由的 404.0 错误。我在 IIS 应用程序的根文件夹中放置了一个静态 test.aspx 文件,该文件返回正确,因此 IIS 似乎只是没有选择路由。我已经尝试了所有可以谷歌的东西,但没有任何东西可以修复它。
这是我的 RouteConfig.cs 代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 WebApiConfig.cs 代码:
using System.Web.Http;
using System.Net.Http.Formatting;
public …Run Code Online (Sandbox Code Playgroud) asp.net asp.net-mvc asp.net-routing asp.net-web-api2 iis-8.5