簡體   English   中英

如何在 ASP.NET MVC 上將 Content-Type 設置為完全“文本/純文本”?

[英]How to set Content-Type to exactly “text/plain” on ASP.NET MVC?

編碼

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return Content("hello", "text/plain");
    }
}

正在響應 header

Content-Type: text/plain; charset=utf-8

我的問題是如何從響應 header Content-Type 中刪除“; charset=utf-8”?

在這里如何從 ASP.NET Core MVC 響應中的 Content-Type 中刪除字符集? 這是如何在 asp.net 內核上執行此操作的。

您可以在Content()之前清除Charset

public ActionResult Index()
{
    Response.Charset = "";
    return Content("hello", "text/plain");
}

請試試這個。

public ActionResult Index()
{
     Response.ContentType = "text/plain";
     return Content("your content");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM