gpt4 book ai didi

c# - net core 2 无法加载资源 : the server responded with a status of 404 (Not Found)

转载 作者:行者123 更新时间:2023-11-30 12:55:35 26 4
gpt4 key购买 nike

我开始在 Google Cloud Platform 上使用 ASP.Net 构建应用程序。Net Core 2.0 MVC模式

我使用两个区域和项目根目录中的一个 HomeControllre

这是一个 ClinicControllel.cs 类

using System.Collections.Generic;
using System.Data.Common;
using System.Threading.Tasks;
using GcpProject_AspNet.Areas.Clinic.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace GcpProject_AspNet.Areas.Clinic.Controllers
{
[Area("Clinic")]
[Route("admin/[controller]")]
//[Route("[controller]")]
//[Authorize]
public class ClinicController : Controller
{
private readonly ILogger _logger;

private readonly DbConnection _connection;

private const int _pageSize = 10;


public ClinicController( DbConnection connection , Microsoft.Extensions.Logging.ILogger<ClinicController> logger1)
{
_logger = logger1;
_connection = connection;
if (_connection.State == System.Data.ConnectionState.Closed)
_connection.Open();
//User.Identities.g
}

[Route("{page:int?}")]
[HttpGet("index")]
public async Task<IActionResult> Index(string userAgent, string nextPageToken)
{
if (string.IsNullOrEmpty(userAgent))
{
userAgent = Request.Headers["User-Agent"];
}

using (var LookUpcommand = _connection.CreateCommand())
{

LookUpcommand.CommandText = @"SELECT * FROM Clinics";
List<string> line = new List<string>();

var reader = await LookUpcommand.ExecuteReaderAsync();

ClinicModel clinicModel = new ClinicModel()
{
ClinicView = new List<ClinicEntry>()
};

List<ClinicEntry> lst = new List<ClinicEntry>();



while (await reader.ReadAsync())
{

//clinicModel.ClinicView.Add(new ClinicEntry()
lst.Add(new ClinicEntry()
{
Clinic_Address = reader.GetString(5),
Clinic_Name = reader.GetString(1),
Phone = reader.GetString(2),
MobilePhone = reader.GetString(3),
E_Mail_Address = reader.GetString(4),
ClinicId = reader.GetInt32(0)
});
clinicModel.ClinicView = lst.ToArray();
}


_logger.LogInformation("Home page hit!");
_connection.Close();
return View(clinicModel);
}
}
[HttpGet("Details/{id}")]
public ActionResult Details(long?id)
{
return View();
}
[HttpGet("Create/{id}")]
public IActionResult Create()
{
return View();
}
}
}

Method Index() - 正确工作其他方法 Create 和 Details 在 Application call Method Details 我在资源管理器中看到“空白页”的地方无法正常工作如果我在部分网络消息中按 F12 出现“无法加载资源:服务器响应状态为 404(未找到)”。我无法在方法 Create() 和 Details() 中设置断点。

文件 starup.cs

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// Only use Console and Debug logging during development.
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
// app.UseExceptionHandler("Clinic/Error");
app.UseGoogleExceptionLogging();
// Send logs to Stackdriver Logging.
loggerFactory.AddGoogle(GetProjectId());
}

// app.UseAuthentication();

app.UseStaticFiles();
app.UseGoogleTrace();

app.UseMvc(routes =>
{
routes.MapRoute("areaAccount", "{area:exists}/{controller=Account}/{action=index}/{id}");
routes.MapRoute("areaClinicIndex", "{area:exists}/{controller=Clinic}/{action=Index}/{id}");
routes.MapRoute("areaClinicDetails", "{area:exists}/{controller=Clinic}/{action=Delails}/{id}");

// for first controller
routes.MapRoute(name: "default",template: "{controller=Home}/{action=Index}/{id?}");
// routes.MapRoute(name:"default",template: "{controller=ApplicationRole}/{action=Index}/{id?}");

});
}

什么是问题??在 Chrome 中 http://localhost:61878/admin/Clinic/index - 正确并正常工作。我在其中选择我看到的项目之一 http://localhost:61878/Clinic/Details/1

最佳答案

Details 操作的路由命名错误。此外,没有创建操作的路径。 StartUp.cs 文件中的路由应该是这样的:

app.UseMvc(routes =>
{
routes.MapRoute("areaAccount", "{area:exists}/{controller=Account}/{action=index}/{id}");
routes.MapRoute("areaClinicIndex", "{area:exists}/{controller=Clinic}/{action=Index}/{id}");
routes.MapRoute("areaClinicDetails", "{area:exists}/{controller=Clinic}/{action=Details}/{id}");
routes.MapRoute("areaClinicDetails", "{area:exists}/{controller=Clinic}/{action=Create}/{id}");

// for first controller
routes.MapRoute(name: "default",template: "{controller=Home}/{action=Index}/{id?}");
// routes.MapRoute(name:"default",template: "{controller=ApplicationRole}/{action=Index}/{id?}")
});

但我真的不建议你使用路由。

关于c# - net core 2 无法加载资源 : the server responded with a status of 404 (Not Found),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47699740/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com