在IIS中启动ASP.NET Core 3.1站点 [英] Starting ASP.NET Core 3.1 Site in IIS

查看:388
本文介绍了在IIS中启动ASP.NET Core 3.1站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法以我期望的方式在IIS(v10)中启动ASP.NET Core 3.1.我将站点发布到与普通站点相同的文件夹,但是当我通过Windows Server 2019 VM在http://localhost:80或https://localhost:443(将IIS站点都绑定到这两个站点)上进行测试时,我刚得到500.19的回应.但是,如果从命令行输入dotnet MyWebApp.dll,则该站点确实出现在https://localhost:5001/.

I have not been able to start my ASP.NET Core 3.1 in IIS (v10) the way I would expect. I publish to site to folders like normal, but when I test from within my Windows Server 2019 VM by going to http://localhost:80 or https://localhost:443 (to both of which the IIS site is bound), I just get a 500.19 response. BUT if from the command line, I enter dotnet MyWebApp.dll, then the site DOES appear at https://localhost:5001/.

这是怎么回事?考虑到端口80已绑定在IIS中,为什么端口80无法自动工作?

What's going on? Why isn't port 80 working automatically, given that it's bound there in IIS?

是否只有通过复制文件并使用IIS才能使它起作用,还是需要使用命令行来启动.NET Core 3.1站点?

Is there some trick to make this work just by copying the files over and using IIS, or am I REQUIRED to use the command line to start a .NET Core 3.1 site?

推荐答案

确保已完成以下操作:

  • 安装了最新的Core托管捆绑包.如果不是,请转到此处查找托管包". https://dotnet.microsoft.com/download/dotnet-core/3.1(您应该定期去那里,大约每个月都有一个新版本,撰写本文时最新为3.1.7)
  • 在应用程序池中,确保未选择选择.NET框架
  • Installed latest Core hosting bundle. If not, go here and look for "Hosting Bundle" https://dotnet.microsoft.com/download/dotnet-core/3.1 (you should go there on regular basis, a new version about every month, latest is 3.1.7 when writing this)
  • In app pool, make sure .NET framework is not selected

发布时,使用

Deployment Mode = Framework-Dependent
Target Runtime = win-x64

保存配置文件后,在发布配置文件中(您在项目文件夹/Properties/PublishProfiles/YourProfileName.pubxml中找到此文件)

In your publish profile (you find this file in project folder /Properties/PublishProfiles/YourProfileName.pubxml) after saving the profile, you'll need

<EnvironmentName>Production</EnvironmentName>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>

InProcess是使用IIS时最快的选项.运行publish时,它将最终像这样在您生成的web.config中结束

InProcess is the fastest option when using IIS. When running publish, this will end up in your generated web.config like this

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath=".\YourWebApp.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess">
      <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
      </environmentVariables>
    </aspNetCore>
  </system.webServer>
</configuration>

在部署到登台服务器时,创建一个新的发布配置文件,并使用

When deploying to a staging server, create a new publish profile, and use

<EnvironmentName>Staging</EnvironmentName>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>

从以下位置获得答案时 https://localhost:5001/ 您正在运行Kestrel,而不是IIS

When you get answer from https://localhost:5001/ you are running Kestrel, not IIS

这篇关于在IIS中启动ASP.NET Core 3.1站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆