简体   繁体   English

如何在 ASP.NET MVC 上将 Content-Type 设置为完全“文本/纯文本”?

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

The code编码

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

is responding with header正在响应 header

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

My question is how to remove "; charset=utf-8" from response header Content-Type?我的问题是如何从响应 header Content-Type 中删除“; charset=utf-8”?

Here How do I remove the charset from Content-Type in a ASP.NET Core MVC response?在这里如何从 ASP.NET Core MVC 响应中的 Content-Type 中删除字符集? it is how to do it on asp.net core.这是如何在 asp.net 内核上执行此操作的。

You can clear the Charset before Content()您可以在Content()之前清除Charset

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

please try this one.请试试这个。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 ASP.NET Core MVC controller 中为重定向设置 Content-Type - How to set Content-Type for a Redirect in ASP.NET Core MVC controller 当Content-Type为text / plain时如何获取.NET MVC绑定POST参数 - How to get .NET MVC to bind POST parameters when Content-Type is text/plain ASP.NET MVC应用程序不输出内容类型标头 - ASP.NET MVC Application not outputting content-type header 如何在 ASP.NET MVC 中使用 GET 请求发送 Content-Type 标头? - How can I send Content-Type header with a GET request in ASP.NET MVC? ASP.Net Core 为 JSON 内容设置 Content-Type 和 Location 标头 - ASP.Net Core set Content-Type and Location headers for JSON content ASP.NET 核心 2 - 缺少内容类型边界 - ASP.NET Core 2 - Missing content-type boundary InvalidOperationException:错误的内容类型:ASP.NET Core - InvalidOperationException: Incorrect Content-Type: ASP.NET Core 如何将内容类型设置为html和纯文本 - How to set content type to html and plain text 如何在asp.net mvc 5中获取文件的内容类型 - How to get the File's Content Type in asp.net mvc 5 如何在asp.net中设置文本框输入type =“ text”? - How to set a text Box Input type=“text” in asp.net?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM