System.InvalidOperationException: 'A path base can only be configured using IApplicationBuilder.UsePathBase().'

我与影子孤独终老i 提交于 2020-06-22 17:45:49

问题


I have an ASP.Net Core 2 Solution running in Docker which is working fine on 1 machine the is running VS 2017 Professional but on another machine running VS 2017 Community I am getting the following error

"System.InvalidOperationException: 'A path base can only be configured using IApplicationBuilder.UsePathBase().'"

when I try and start or debug the solution using docker. If I start the solution with IIS Express it works fine.

There is nothing special about my project:

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();
    }
}

I also get this pop up in a new window:

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()

Everything i've read on this issue don't seem related. Any ideas?


回答1:


Try adding a base path to your applicationUrl in your launchOptions while running.

Reference: Check Here




回答2:


I was setting the relative path within applicationUrl in launchSettings.json which was causing the error:

"applicationUrl": "https://localhost:5001/admin",

I changed that back to the root URL and instead added a launchUrl with the path which fixed the error and launched the path I wanted on start:

"applicationUrl": "https://localhost:5001",
"launchUrl": "admin"


来源:https://stackoverflow.com/questions/46749411/system-invalidoperationexception-a-path-base-can-only-be-configured-using-iapp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!