I have the below code that runs successfully, receives Http requests but returns 404. I created a .NET Console App and installed Microsoft.AspNetCore.App package. I see the WebApplication is receiving the requests but always responds with 404.
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using AppHostTest;
var testBuilder = WebApplication.CreateBuilder(new WebApplicationOptions ());
testBuilder.Services.AddRazorPages();
testBuilder.Services.AddTransient<IVehicle, Car>();
var testapp = testBuilder.Build();
testapp.UseHttpsRedirection();
testapp.UseStaticFiles();
testapp.UseRouting();
testapp.UseAuthorization();
testapp.MapRazorPages();
testapp.Run();
尽管上述法典与你在利用网络应用模板把项目混为一谈时所看到的完全相同,但行为并不相同。
任何帮助了解上述安排的错误之处都会受到高度赞赏。
我尝试安装微软。 AspNetCode.Mvc 包裹,在测试应用方面增加AddMvc()服务,使用Mvc(),但并未奏效和行为。
更新:
我看见通过手法创建的WebApplicationBuilder,把网络服务器作为复合FileProvider作为万维网网路仪,作为wwwroot。
whereas, the WebApplicationBuilder created by ConsoleApp populates the WebRootFileProvider as NullFileProvider and WebRootPath as null.