.NET Core3.0 ASP.NET Web AP仅在部署到IIS时才能在控制器操作上获取404

问题描述

我拥有所有aspnetcore movdulev2,服务器上安装的所有必需软件。 IIS可以识别该网站,因此我放置了一个默认页面。唯一的问题是,当我从webAPi应用程序的根应用程序路径中获取控制器/动作时,我得到404。我尝试了不同格式的路由,包括Microsoft的默认.Net core 3应用程序。一切都可以在我的本地IIS Express上运行,但不能在IIS上运行。应用程序池是.NttCore NoManaged Apppool。我没有任何权限问题。 我的 program .cs 和Web.config如下:

 public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseContentRoot(Directory.GetCurrentDirectory());
                    webBuilder.UseStartup<Startup>();
                    
                });
    }


<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="c:\program files\dotnet\dotnet.exe" verb="*" 
        modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\WebApplication2Test.dll" stdoutLogEnabled="false" 
       stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>

如果有人可以提供指导,那将有所帮助。

解决方法

从您的frt日志中,负责asp.net的路由模块不起作用。该请求应该已经进入路由管道,但是转到了iis的静态文件处理模块。 iis根据url在文件系统中查找,但未找到它,因此报告了404。 。您可以使用以下配置强制路由模块工作。

<system.webServer>
    .....
    <modules runAllManagedModulesForAllRequests="true" />
    .....
</system.webServer>

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...