![](/img/trans.png)
[英]How to return a string response from a .NET Core API endpoint that has a quotations in it?
[英]Dot Net Core Web API Return Response From Endpoint
我正忙於創建一個非常簡單的 Dot Net Core Web API (Dot Net 5),我遇到了一個奇怪的問題,我無法讓端點返回響應。
我試過用
await context.Response.WriteAsync("Hello World!");
根據文檔,但我收到錯誤
'HttpResponse' does not contain a definition for 'WriteAsync'
這是完整的Startup.cs
代碼
public class Startup {
public Startup(IConfiguration configuration) {
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services) { }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
app.UseRouting();
app.UseEndpoints(endpoints => {
endpoints.MapGet("/test", async context => {
//Console.WriteLine("Exec Test");
await context.Response.WriteAsync("Hello World!");
});
});
}
}
我確定我缺少一些東西
添加 Microsoft.AspNetCore.Http.Abstractions.dll 的依賴項,其中包含您正在尋找的基於 HttpResponse 的 WriteAsync 方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.