【问题标题】:How to set Content-Type to exactly "text/plain" on ASP.NET MVC?如何在 ASP.NET MVC 上将 Content-Type 设置为完全“文本/纯文本”?
【发布时间】:2020-02-18 13:44:21
【问题描述】:

代码

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

正在响应标题

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

我的问题是如何从响应标头 Content-Type 中删除“;charset=utf-8”?

这里How do I remove the charset from Content-Type in a ASP.NET Core MVC response?是如何在asp.net core上做的。

【问题讨论】:

  • 为什么要删除它?
  • @Moo-Juice,客户希望如此
  • @thirdDeveloper,不,它不是重复的,关于核心
  • 删除它不会有任何效果,客户只会假设charset=utf8。毫无意义。

标签: c# asp.net-mvc asp.net-mvc-5 http-headers content-type


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    请试试这个。

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

    【讨论】:

    • 你怎么能说没有帮助?
    • 我的意思是它对我不起作用 - 在响应标头上存在字符集部分
    猜你喜欢
    • 2017-02-20
    • 2011-12-25
    • 1970-01-01
    • 2011-12-25
    • 2021-07-29
    • 2012-05-22
    • 1970-01-01
    • 1970-01-01
    • 2013-09-09
    相关资源
    最近更新 更多