将.NET Core 3.0 Web应用程序从IIS Express迁移到IIS时遇到问题

我已经在服务器上开发了一个针对.NET Core 3.0的Web应用程序。该项目基于Visual Studio 2019的ASP .NET Core Web应用程序模板。

将.NET Core 3.0 Web应用程序从IIS Express迁移到IIS时遇到问题

我选择了ASP.NET Core 3.0,并指定该应用程序将实现单个用户帐户(身份)。

发展一直很好。我更改了连接字符串,以便在我的应用程序数据库中构建身份表。我已经开发了几个星期,在IIS Express中运行和调试。

确定,现在是时候进行部署了。我在目标服务器上设置了Web Deploy,创建了部署模板并发布。该Web应用程序是在目标服务器上创建的。

但是,我收到了运行时错误:

HTTP错误500.30-ANCM进程内启动失败

Windows事件日志中的诊断将我指向特定的行号,即Startup.cs中的第77行

将.NET Core 3.0 Web应用程序从IIS Express迁移到IIS时遇到问题

app.UseRouting();

app.UseAuthentication();
app.UseIdentityServer();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
    endpoints.MapControllerRoute(
        name: "default",pattern: "{controller}/{action=Index}/{id?}");
    endpoints.MapRazorPages();
});

因此,我退出了目标部署,以查看是否可以在本地开发工作站上的IIS上运行该应用程序。我创建了一个名为cashflow的应用程序,并将其映射到c:\ inetpub \ cashflow。

将.NET Core 3.0 Web应用程序从IIS Express迁移到IIS时遇到问题

我创建了一个基于文件的部署,并看到所有应用程序文件都复制到c:\ inetpub \ cashflow中。

我浏览到http://localhost/cashflow,并得到完全相同的错误:

HTTP错误500.30-ANCM进程内启动失败

这是我在Windows事件日志中找到的内容:

抱歉,巨大的堆栈跟踪。我认为输出中最相关的项目是对第77行失败的引用。

,位于C:\ Users \ Yossi \ source \ repos \ Cashflow \ Startup.cs:line 77中的Cashflow.Startup.Configure(IApplicationBuilder应用程序,IWebHostEnvironment env)

我想我缺少支持app.UseAuthorization();必需的重要内容。你能帮我这个忙吗?谢谢!

Application '/LM/W3SVC/1/ROOT/cashflow' with physical root 'C:\inetpub\wwwroot\cashflow\' hit unexpected managed exception,exception code = '0xe0434352'. First 30KB characters of captured stdout and stderr logs:
Application startup exception: System.InvalidOperationException: Key type not specified.
   at microsoft.AspNetCore.Apiauthorization.IdentityServer.ConfigureSigningCredentials.LoadKey()
   at microsoft.AspNetCore.Apiauthorization.IdentityServer.ConfigureSigningCredentials.Configure(ApiauthorizationOptions options)
   at microsoft.Extensions.Options.OptionsFactory`1.Create(String name)
   at microsoft.Extensions.Options.OptionsManager`1.<>c__DisplayClass5_0.<Get>b__0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication,Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at microsoft.Extensions.Options.OptionsCache`1.GetOrAdd(String name,Func`1 createOptions)
   at microsoft.Extensions.Options.OptionsManager`1.Get(String name)
   at microsoft.Extensions.Options.OptionsManager`1.get_Value()
   at microsoft.Extensions.DependencyInjection.IdentityServerBuilderConfigurationExtensions.<>c.<AddClients>b__7_1(IServiceProvider sp)
   at microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite,RuntimeResolverContext context)
   at microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite,TArgument argument)
   at microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite,RuntimeResolverContext context,ServiceProviderEnginescope serviceProviderEngine,RuntimeResolverLock lockType)
   at microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite,RuntimeResolverContext context)
   at microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite,TArgument argument)
   at microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite,TArgument argument)
   at microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite,TArgument argument)
   at microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite,ServiceProviderEnginescope scope)
   at microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEnginescope scope)
   at microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType,ServiceProviderEnginescope serviceProviderEnginescope)
   at microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEnginescope.GetService(Type serviceType)
   at microsoft.AspNetCore.Builder.IdentityServerApplicationBuilderExtensions.TestService(IServiceProvider serviceProvider,Type service,ILogger logger,String message,Boolean doThrow)
   at microsoft.AspNetCore.Builder.IdentityServerApplicationBuilderExtensions.Validate(IApplicationBuilder app)
   at microsoft.AspNetCore.Builder.IdentityServerApplicationBuilderExtensions.UseIdentityServer(IApplicationBuilder app,IdentityServerMiddlewareOptions options)
   at Cashflow.Startup.Configure(IApplicationBuilder app,IWebHostEnvironment env) in C:\Users\Yossi\source\repos\Cashflow\Startup.cs:line 77
   at System.RuntimeMethodHandle.InvokeMethod(Object target,Object[] arguments,Signature sig,Boolean constructor,Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,Bindingflags invokeAttr,Binder binder,Object[] parameters,CultureInfo culture)
   at microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance,IApplicationBuilder builder)
   at microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
   at microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
   at microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
   at microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at microsoft.AspNetCore.Hosting.WebHost.BuildApplication()
crit: microsoft.AspNetCore.Hosting.WebHost[6]
      Application startup exception
System.InvalidOperationException: Key type not specified.
   at microsoft.AspNetCore.Apiauthorization.IdentityServer.ConfigureSigningCredentials.LoadKey()
   at microsoft.AspNetCore.Apiauthorization.IdentityServer.ConfigureSigningCredentials.Configure(ApiauthorizationOptions options)
   at microsoft.Extensions.Options.OptionsFactory`1.Create(String name)
   at microsoft.Extensions.Options.OptionsManager`1.<>c__DisplayClass5_0.<Get>b__0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication,Boolean doThrow)
   at microsoft.AspNetCore.Builder.IdentityServerApplicationBuilderExtensions.Validate(IApplicationBuilder app)
   at **microsoft.AspNetCore.Builder.IdentityServerApplicationBuilderExtensions.UseIdentityServer(IApplicationBuilder app,IWebHostEnvironment env) in C:\Users\Yossi\source\repos\Cashflow\Startup.cs:line 77**
   at System.RuntimeMethodHandle.InvokeMethod(Object target,IApplicationBuilder builder)
   at microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
   at microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
   at microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
   at microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at microsoft.AspNetCore.Hosting.WebHost.BuildApplication()
Unhandled exception. System.InvalidOperationException: Key type not specified.
   at microsoft.AspNetCore.Apiauthorization.IdentityServer.ConfigureSigningCredentials.LoadKey()
   at microsoft.AspNetCore.Apiauthorization.IdentityServer.ConfigureSigningCredentials.Configure(ApiauthorizationOptions options)
   at microsoft.Extensions.Options.OptionsFactory`1.Create(String name)
   at microsoft.Extensions.Options.OptionsManager`1.<>c__DisplayClass5_0.<Get>b__0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication,IApplicationBuilder builder)
   at microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
   at microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
   at microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
   at microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at microsoft.AspNetCore.Hosting.WebHost.BuildApplication()
   at microsoft.AspNetCore.Hosting.WebHost.StartAsync(CancellationToken cancellationToken)
   at microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host,CancellationToken token,String startupMessage)
   at microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host,CancellationToken token)
   at microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
   at Cashflow.Program.Main(String[] args) in C:\Users\Yossi\source\repos\Cashflow\Program.cs:line 17
hxcn2004 回答:将.NET Core 3.0 Web应用程序从IIS Express迁移到IIS时遇到问题

我在这里找到了答案:

Adding Identityserver authentication to net core 3 app fails with 'Key type not specified.'

简而言之,解决方案是将证书放在应用程序的子文件夹中,并将以下内容添加到appsettings.json中。

  "IdentityServer": {
    "Key": {
      "Type": "File","FilePath": "Certificates\\certificatefile.pfx","Password": "veryDifficultPassword"
    }
  }

有了这个,我现在可以启动应用程序:

C:\inetpub\cashflow>cashflow.exe
Hosting environment: Production
Content root path: C:\inetpub\cashflow
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
本文链接:https://www.f2er.com/2909805.html

大家都在问