我在Docker中运行的ASP.Net Core 2解决方案在运行VS 2017 Professional的1台计算机上正常运行但在另一台运行VS 2017社区的计算机上运行时出现以下错误
“System.InvalidOperationException:'路径库只能是 使用IApplicationBuilder.UsePathBase()配置。'“
当我尝试使用docker启动或调试解决方案时。如果我使用IIS Express启动解决方案,它可以正常工作。
我的项目没有什么特别之处:
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run(); // <- Exception happens here
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.CaptureStartupErrors(true)
.UseStartup<Startup>()
.Build();
}
public class Startup
{
public Startup(IHostingEnvironment env)
{
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
我也会在新窗口中弹出这个:
crit: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.
System.InvalidOperationException: A path base can only be configured using IApplicationBuilder.UsePathBase().
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.<BindAddressAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.<BindAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.<BindAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<StartAsync>d__21`1.MoveNext()
我在这个问题上读过的所有内容似乎都没有关系。有什么想法吗?
答案 0 :(得分:9)
我正在applicationUrl
的{{1}}中设置相对路径,这导致了错误:
launchSettings.json
我将其改回了根URL,而是添加了一个"applicationUrl": "https://localhost:5001/admin",
,其路径可修复错误并在启动时启动了我想要的路径:
launchUrl
答案 1 :(得分:4)
尝试在运行时在launchOptions中为applicationUrl添加基本路径。
参考:Check Here