[英]Send Html in .Net Core 2.2
我正在嘗試在“啟動”類的這一行獲取html(在瀏覽器中),但未將其僅顯示為純文本。 在本地主機https:// localhost:44378 /上 (應用程序默認)
在.net core 2.2中
public void Configure(IApplicationBuilder app)
{
app.Run(async (context) =>
{
//send html here but shows simple text
await context.Response.WriteAsync("htmls here <br>");
});
}
有一個簡單的修復程序,因此@Tseng在注釋中很容易指出:您需要將Response的Content-Type
標頭設置為text/html
,這是可以做到的:
app.Run(async (context) =>
{
// Or you could use indexer like so: context.Response.Headers["Content-Type"] = "text/html"
context.Response.Headers.Add("Content-Type", "text/html");
await context.Response.WriteAsync("htmls here <br>");
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.