System.InvalidOperationException:'只能使用IApplicationBuilder.UsePathBase()配置路径基础。“

问题描述:

我在码头工人的ASP.Net的Core 2解决方案运行的是1台机器上工作正常的运行VS 2017年专业,但VS运行2017年社区我收到以下错误System.InvalidOperationException:'只能使用IApplicationBuilder.UsePathBase()配置路径基础。“

“系统另一台机器上。 InvalidOperationException异常:“A路径基只能是 使用IApplicationBuilder.UsePathBase配置()。””

当我尝试开始或使用搬运工调试解决方案。如果我使用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

你检查了吗? https://*.com/questions/46406525/net-core-2-0-basepath-error –

尝试在运行时向launchOptions中的applicationUrl添加基路径。

参考:Check Here

+0

呃...我也看过这个问题。直到我试图运行IISExpress,它的工作原理才有意义。谢谢!它实际上是“applicationUrl”:“http:// localhost:32768/api”,我在docker选项中修改为“applicationUrl”:“http:// localhost:32768 /”。 –