IIS 10 上的 .NET MVC Core 2 部署问题

.NET MVC Core 2 Deployment Issue on IIS 10

我正在尝试将我的 ASP.NET MVC Core 2 站点部署到 Windows Server 2016 服务器 运行 IIS 10 我在应用程序日志中收到以下错误。

我研究了这个问题,发现这个 问题的答案是 "As VS2017 RC is shipped with the new version of .NET Core SDK (.NET Core 1.0.4 SDK 1.0.1), you need to update framework on server as well."

我已经尝试按照上面的答案在服务器上安装 SDK 和运行时,但是当我导航到该站点时仍然收到错误消息。

我该如何解决这个问题?

Faulting application name: dotnet.exe, version: 2.0.25816.2, time stamp: 0x59e535ea
Faulting module name: coreclr.dll, version: 4.6.25815.2, time stamp: 0x59e2b767
Exception code: 0xc00000fd
Fault offset: 0x000000000008247a
Faulting process id: 0x1c68
Faulting application start time: 0x01d36aeaea2429cf
Faulting application path: C:\Program Files\dotnet\dotnet.exe
Faulting module path: C:\Program Files\dotnet\shared\Microsoft.NETCore.App.0.3\coreclr.dll
Report Id: 100b3c83-7509-487e-b1cd-6a0357f8b7e7
Faulting package full name: 
Faulting package-relative application ID: 

运行 以下命令揭示了真正的错误:

C:\Windows\system32>"C:\Program Files\dotnet\dotnet" C:\inetpub\wwwroot\{YOUR_IIS_SITE_NAME}\{YOUR_PROJECT_NAME}.dll

命令提示符的结果如下,告诉我我的连接字符串有错误:

C:\Windows\system32>"C:\Program Files\dotnet\dotnet" C:\inetpub\wwwroot\www_projectx_com\ProjectX.dll
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using 'C:\Users\darchual\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[58]
      Creating key {70b30c91-49df-45be-95cc-2e681b5cde76} with creation date 2017-12-04 16:34:08Z, activation date 2017-12-04 16:34:08Z, and expiration date 2018-03-04 16:34:08Z.
info: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[39]
      Writing data to file 'C:\Users\darchual\AppData\Local\ASP.NET\DataProtection-Keys\key-70b30c91-49df-45be-95cc-2e681b5cde76.xml'.

Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: connectionString
   at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)
   at Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer(DbContextOptionsBuilder optionsBuilder, String connectionString, Action`1 sqlServerOptionsAction)
   at ProjectX.Startup.<ConfigureServices>b__4_0(DbContextOptionsBuilder options) in C:\VSO\Avvenire Source\Internal\Project X\ProjectX\Startup.cs:line 35
   ... truncated for brevity ...

一次解决申请运行完美!

此外,请记住(在 IIS 上托管 MVC 核心应用程序时)相应地更新您的 Program.cs 文件:

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

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();
}

最后但同样重要的是,我需要通过添加一个新创建的 SQL 用户来修复连接字符串(仅使用集成安全性是行不通的):

"ConnectionStrings": {
    "DefaultConnection": "Server={theserver};Database={thedatabase};MultipleActiveResultSets=true;User Id={theusername};Password={thepassword};"
},

参考。