我在我的解决方案中创建了一个新项目。该项目是ASP.NET核心应用程序。
问题是当我点击IISExpress时

要开始调试,我会遇到以下错误:

这些是项目属性Debug


我不知道该怎么办..。有人能帮我吗?
编辑这是我的launchSettings.json
{
"iisSettings": {
"windowsAuthentication": true,
"anonymousAuthentication": true,
"iis": {
"applicationUrl": "http://localhost:8083/backendCore",
"sslPort": 0
},
"iisExpress": {
"applicationUrl": "http://localhost:8083",
"sslPort": 0
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "backend",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"backendCore": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
},
"prova": {
"commandName": "IIS",
"launchBrowser": true,
"launchUrl": "backend"
}
}
}和startup.cs
namespace backendCore
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
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.AddControllers();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UsePathBase("/backend"); //Add this line
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}这是我的控制器的代码片段(但后端永远不会停在这里)
namespace backendCore.Controllers
{
public class AuthController : ControllerBase
{
[Route("api/Auth/{language}/guest")]
[HttpPost]
public ActionResult guestAuth(string language)
{
return Ok(true);
}
}发布于 2021-07-06 20:20:23
更改startup.cs文件Configure方法中的以下代码
if (env.IsDevelopment())
{
app.UsePathBase("/backend"); //Add this line
app.UseDeveloperExceptionPage();
}这将添加一个中间件,该中间件从请求路径中提取指定的路径基并将其推迟到请求路径基中。这仅适用于开发环境,如果您的生产环境也配置了后端子文件夹,请将其放在if条件之外。
发布于 2021-07-06 22:57:30
更改您的代码。希望能在你的案例中起作用!
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddMvc(options =>
{
options.EnableEndpointRouting = false;
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UsePathBase("/backend"); //Add this line
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseMvcWithDefaultRoute();
}发布于 2021-07-07 01:17:04
HTTP POST vs GET
您的终结点是一个[HttpPost],您不能在浏览器中输入该URL并导航到它。在浏览器中导航到URL是一个GET请求。
路由
您已经共享了控制器和终结点的(部分)代码,如下所示:
[Route("api/Auth/{language}/guest")]
完全匹配:http://localhost:8083/api/Auth/{language}/guest
导航到http://localhost:8083/backend将导致一个404,因为它与确切的路径不匹配。路由不覆盖路径的一部分。
UsePathBase
我不确定你试图用UsePathBase实现什么,这应该只在代理场景下工作时才有必要(例如,使用nginx或Apache托管),你没有提到任何需要使用它的要求,所以我会删除它,因为它只是在混水摸鱼。
参考
我相信这会产生更多的问题,所以请适当地编辑你的帖子并询问。
https://stackoverflow.com/questions/68242885
复制相似问题