.NET Core 2.0 BasePath错误

编程入门 行业动态 更新时间:2024-10-26 00:28:45
本文介绍了.NET Core 2.0 BasePath错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

刚刚启动了一个新的.NET Core 2.0应用程序,但是突然出现了奇怪的行为,似乎什么也找不到。

Just started a fresh .NET Core 2.0 app, but getting weird sudden behaviour, can't seem to find anything.

点击我的 BuildWebHost()中的 .Run()。:

The following error pops up when hitting the .Run() of my BuildWebHost().:

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() 'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.0\System.Diagnostics.Tools.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Application Insights Telemetry (unconfigured): {"name":"Microsoft.ApplicationInsights.Dev.Exception","time":"2017-09-25T13:26:29.6923656Z","tags":{"ai.application.ver":"1.0.0.0","ai.internal.sdkVersion":"aspnet5c:2.1.1"},"data":{"baseType":"ExceptionData","baseData":{"ver":2,"properties":{"{OriginalFormat}":"Unable to start Kestrel.","CategoryName":"Microsoft.AspNetCore.Server.Kestrel","Exception":"System.InvalidOperationException: A path base can only be configured using IApplicationBuilder.UsePathBase().\r\n at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.<BindAddressAsync>d__7.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.<BindAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.<BindAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<StartAsync>d__21`1.MoveNext()","AspNetCoreEnvironment":"Development","DeveloperMode":"true"},"exceptions":[{"id":47609378,"typeName":"System.InvalidOperationException","message":"Unable to start Kestrel.","hasFullStack":true,"parsedStack":[{"level":0,"method":"Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder+<BindAddressAsync>d__7.MoveNext","assembly":"Microsoft.AspNetCore.Server.Kestrel.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60"},{"level":1,"method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"},{"level":2,"method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"},{"level":3,"method":"Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder+AddressesStrategy+<BindAsync>d__2.MoveNext","assembly":"Microsoft.AspNetCore.Server.Kestrel.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60"},{"level":4,"method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"},{"level":5,"method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"},{"level":6,"method":"Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder+<BindAsync>d__0.MoveNext","assembly":"Microsoft.AspNetCore.Server.Kestrel.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60"},{"level":7,"method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"},{"level":8,"method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"},{"level":9,"method":"Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer+<StartAsync>d__21`1.MoveNext","assembly":"Microsoft.AspNetCore.Server.Kestrel.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60"}]}],"severityLevel":"Critical"}}} The thread 0x1d7c has exited with code 0 (0x0). The thread 0x25c0 has exited with code 0 (0x0). Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll An unhandled exception of type 'System.InvalidOperationException' occurred in System.Private.CoreLib.dll A path base can only be configured using IApplicationBuilder.UsePathBase().

这是我的程序。cs

public class Program { public static void Main(string[] args) { BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .Build(); }

这是我的Startup.cs

Here's my Startup.cs

public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; set; } public void ConfigureServices(IServiceCollection services) { services.AddMvc(); //Swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "2Commit Blogpost API", Version = "v1" }); }); //Mediatr services.AddScoped<IMediator, Mediator>(); services.AddTransient<SingleInstanceFactory>(sp => sp.GetService); services.AddTransient<MultiInstanceFactory>(sp => sp.GetServices); services.AddMediatorHandlers(typeof(Startup).Assembly); //MongoDB services.Configure<MongoSettings>(s => { s.Database = Configuration.GetSection("MongoConnection:Database").Value; }); services.AddSingleton<IMongoClient, MongoClient>(client => new MongoClient(Configuration.GetSection("MongoConnection:ConnectionString").Value)); //BL services.AddTransient<IUserService, UserService>(); //DAL services.AddTransient<IRepository, MongoRepository>(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { //Swagger app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "BlogPost API"); }); app.UseMvc(); } }

似乎无法绕过这一个!

更新1:

该错误仅在从命令行运行我的项目时以及运行时弹出它通过IIS Express,没有错误。

The error only pops up when running my project from the command line, when running it trough IIS Express, no errors.

这是我的启动设置

{ "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "localhost:51592/swagger", "sslPort": 0 } }, "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "API": { "commandName": "Project", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, "applicationUrl": "localhost:5000/swagger" } } }

推荐答案

好,在1.X中,您可以在从co运行时,在launchOptions中向applicationUrl添加基本路径。 mmand行,现在仅在使用IIS时有效。

OK, in 1.X you could just add a base path to your applicationUrl in your launchOptions while running from command line, now it only works when using IIS.

在我的launchSettings中,更改了我的CLI配置文件,从使用

in my launchSettings, changing my CLI profile from using

applicationUrl: http:// localhost:5000 / swagger

applicationUrl: http:// localhost:5000

做到了。

更多推荐

.NET Core 2.0 BasePath错误

本文发布于:2023-11-08 11:03:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569198.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   Core   NET   BasePath

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!