【发布时间】:2019-02-08 15:20:56
【问题描述】:
发布应用程序后,我无法启动 dotnet 核心应用程序。虽然dotnet run 在开发环境中启动应用程序,但在发布后尝试启动应用程序只会抛出此错误。
crit: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.
System.FormatException: Invalid URL: 'http:////*:80'.
at Microsoft.AspNetCore.Server.Kestrel.Core.ServerAddress.FromUrl(String url)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.ParseAddress(String address, Boolean& https)
at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Load()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.ValidateOptions()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
Unhandled Exception: System.FormatException: Invalid URL: 'http:////*:80'.
at Microsoft.AspNetCore.Server.Kestrel.Core.ServerAddress.FromUrl(String url)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.ParseAddress(String address, Boolean& https)
at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Load()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.ValidateOptions()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.StartAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String shutdownMessage)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
at NiqVive.Api.Program.Main(String[] args) in /home/sav/github/nForTics/NiqVive/NiqVive.Api/Program.cs:line 12
[1] 29044 abort (core dumped) dotnet NiqVive.Api.dll
这是我的 Program.cs
namespace NiqVive.Api
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(options =>
{
options.Listen(IPAddress.Any, 5007);
options.Limits.MaxRequestBodySize = null;
})
.UseDefaultServiceProvider(options => {
options.ValidateScopes = false;
});
}
}
--硬件 版本:2.1.401
运行时环境: 操作系统名称:ubuntu 操作系统版本:18.04 RID:ubuntu.18.04-x64 基本路径:/usr/share/dotnet/sdk/2.1.401/
如果我发布应用程序,它不会启动。
【问题讨论】:
-
你有 appsetttings.json 文件吗?您可能想使用
UseUrls方法:docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/… -
由于它是开源的,github.com/aspnet/KestrelHttpServer/blob/release/2.1/src/… 检查地址是如何被 Kestrel 提取的,然后检查你的环境。
-
谢谢,appsettings 保存了信息..