我已经创建了一个 ASP.NET Core 8 Web API 项目。我program.cs
用所需的代码更新了,但是没有命中断点,我可以在的入口处调试代码program.cs
。
proposalApi.MapGet("/proposals", () => {
try
{
DirectoryInfo dir = new DirectoryInfo(ProposalsDirectory);
var files = dir.GetFiles("*.txt").Select(x => x.Name).ToList();
var data = files.Select(x => new
{
index = int.Parse(new String(x.Where(Char.IsDigit).ToArray())),
value = x
}).OrderByDescending(x => x.index).Select(x => x.value).ToArray();
return data.Count() == 0 ? Results.NotFound() : Results.Ok(data);
}
catch (Exception ex)
{
return ErrorDetails(ex);
}
});
proposalApi.MapGet("/proposals/{fileName}", (int fileName) => {
try
{
string content = File.ReadAllText(ProposalsDirectory + fileName);
return Results.Ok(content);
}
catch (Exception ex)
{
return ErrorDetails(ex);
}
});
尝试的 URL:
https://本地主机:44312 /提案/提案
https://localhost:44312/提案/
断点:
Web api项目代码路径(fiddle):
https://github.com/nitinjs/upworkify/tree/main/ProposalAPI.Core