本文介绍了System.InvalidOperationException:'只能使用IApplicationBuilder.UsePathBase()配置路径库.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Docker中运行的ASP.Net Core 2解决方案,它在运行VS 2017 Professional的一台机器上运行正常,但是在运行VS 2017 Community的另一台机器上却出现以下错误

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

当我尝试使用docker启动或调试解决方案时.如果我使用IIS Express启动解决方案,则可以正常运行.

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?

推荐答案

尝试在运行时在launchOptions中向applicationUrl添加基本路径.

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

参考:在此处检查

这篇关于System.InvalidOperationException:'只能使用IApplicationBuilder.UsePathBase()配置路径库.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 10:51