简体   繁体   English

Net Core 部署的应用程序在 IIS 上引发错误 404

[英]Net Core deployed app throws error 404 on IIS

I'm working on a web app with Angular 7 as Front End and Net Core 3.0 as Back End.我正在使用 Angular 7 作为前端和 Net Core 3.0 作为后端的网络应用程序。 Everything works fine in development mode and I am able to call the URI from the front end, directly from the browser and from Postman as well https://localhost:5001/api/controller/params在开发模式下一切正常,我可以从前端直接从浏览器和邮递员以及https://localhost:5001/api/controller/params调用 URI

For demonstration purposes I have to do a release right now.出于演示目的,我必须立即发布。 From CLI and Visual Studio (Mac) everything looks OK: folder generated with path project/bin/Release/netcoreapp3.0/publish/all the .dll files, web.config, etc.从 CLI 和 Visual Studio (Mac) 看起来一切正常:使用路径 project/bin/Release/netcoreapp3.0/publish/all the .dll files、web.config 等生成的文件夹。

However, when published on IIS if I call https://appname.myserver.com/api/controller/params or http the browser gives me a 404 error.但是,在 IIS 上发布时,如果我调用https://appname.myserver.com/api/controller/params或 http,浏览器会给我一个 404 错误。 If I call http://appname.myserver.com/ I get the blue IIS screen with the welcome message in different languages.如果我调用http://appname.myserver.com/,我会看到带有不同语言的欢迎消息的蓝色 IIS 屏幕。

The IIS configuration followed Microsoft instructions found here: https://docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-3.1&tabs=visual-studio IIS 配置遵循此处找到的 Microsoft 说明: https : //docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-3.1&tabs=visual-studio

I'm not publishing directly to IIS since I don't have access to the server, however I did supervise the setup process remotely.我没有直接发布到 IIS,因为我无权访问服务器,但是我确实远程监督了安装过程。

I've looked over the web and someone suggested to do this in my Program.cs file:我查看了网络,有人建议在我的 Program.cs 文件中执行此操作:

    namespace BackEnd
{
    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.UseStartup<Startup>();
                    webBuilder.UseIISIntegration();
                    webBuilder.UseKestrel();
                    webBuilder.UseUrls("http://localhost:5000", "https://localhost:5001");
                });
    }
}

And the web.config looks like this: web.config 看起来像这样:

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

Here's the applicationHosting.config:这是 applicationHosting.config:

<site name="backendv2.hawk-poslatinoamericana.com.mx" id="10" serverAutoStart="true">
            <application path="/" applicationPool="No Managed Code" enabledProtocols="http">
                <virtualDirectory path="/" physicalPath="C:\HostingSpaces\poslatino\backendv2.hawk-poslatinoamericana.com.mx\wwwroot" />
            </application>
            <bindings>
                <binding protocol="https" bindingInformation="169.57.1.244:5001:backendv2.hawk-poslatinoamericana.com.mx" sslFlags="0" />
                <binding protocol="http" bindingInformation="169.57.1.244:5000:backendv2.hawk-poslatinoamericana.com.mx" />
                <binding protocol="http" bindingInformation="169.57.1.244:5000:www.backendv2.hawk-poslatinoamericana.com.mx" />
                <binding protocol="https" bindingInformation="169.57.1.244:5001:www.backendv2.hawk-poslatinoamericana.com.mx" sslFlags="0" />
            </bindings>
            <logFile directory="C:\HostingSpaces\poslatino\backendv2.hawk-poslatinoamericana.com.mx\logs" enabled="true" />
            <traceFailedRequestsLogging enabled="true" directory="C:\inetpub\logs\FailedReqLogFiles" maxLogFiles="50" />
            <limits connectionTimeout="00:04:00" />
        </site>

But so far, no luck and I am out of ideas.但到目前为止,没有运气,我没有想法。

According to your description, I found you bind the two domain with the 5000 and 5001 port not the 80 port.根据你的描述,我发现你绑定了两个域的5000和5001端口,而不是80端口。

If you call https://appname.myserver.com , it will access the server's 443 port, not the 5000 and 5001 port.如果您调用https://appname.myserver.com ,它将访问服务器的 443 端口,而不是 5000 和 5001 端口。 If you call http://appname.myserver.com , it will access the server's 80 port.如果您调用http://appname.myserver.com ,它将访问服务器的 80 端口。

Besides, if you want to host the asp.net core application in the IIS, you should firtly create the web applicatio by using below steps:此外,如果您想在 IIS 中托管 asp.net 核心应用程序,您应该首先使用以下步骤创建 Web 应用程序:

On the hosting system, create a folder to contain the app's published folders and files.在托管系统上,创建一个文件夹以包含应用程序的已发布文件夹和文件。 In a following step, the folder's path is provided to IIS as the physical path to the app.在接下来的步骤中,文件夹的路径作为应用程序的物理路径提供给 IIS。 For more information on an app's deployment folder and file layout, see ASP.NET Core directory structure.有关应用的部署文件夹和文件布局的详细信息,请参阅 ASP.NET Core 目录结构。

In IIS Manager, open the server's node in the Connections panel.在 IIS 管理器中,在连接面板中打开服务器的节点。 Right-click the Sites folder.右键单击站点文件夹。 Select Add Website from the contextual menu.从上下文菜单中选择添加网站。

Provide a Site name and set the Physical path to the app's deployment folder.提供站点名称并将物理路径设置为应用程序的部署文件夹。 Provide the Binding configuration and create the website by selecting OK:提供绑定配置并通过选择确定来创建网站:

Notice: the port is 80 not 5001注意:端口是80不是5001

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM