NET7
app.MapGet("/test_ok", () =>
{
return TypedResults.Ok<Data>(new Data { Id = 1, Name = "测试产品", Price = 10.2m });
});
app.MapGet("/test_json", () =>
{
return TypedResults.Json<Data>(new Data { Id = 1, Name = "测试产品", Price = 10.2m });
});
app.MapGet("/test_localredirect", () =>
{
return TypedResults.LocalRedirect("/test_ok");
});
app.MapGet("/test_redirect", () =>
{
return TypedResults.Redirect("https://www.google.com");
});
app.MapGet("/test_file", () =>
{
var bytes = "这是一个测试"u8;//这个需要C#11,项目文件的PropertyGroup节点中增加<LangVersion>preview</LangVersion>
return TypedResults.File(bytes, contentType: "text", fileDownloadName: "test.txt");
});
app.MapGet("/test_physicalfile", () =>
{
return TypedResults.PhysicalFile(Directory.GetCurrentDirectory() + "/download.txt", contentType: "text", fileDownloadName: "download.txt");
});
文档更新时间: 2022-05-20 13:22 作者:admin