。net核心支持响应标头空白值,当我们设置空白值以使完整的响应变为空白时,

问题描述 投票:0回答:1

在控制器中,当我们将响应标题值设置为空白时,完成响应将变为空白。该值是根据条件而来的,因此一段时间后该值可以为空。

我的控制器动作代码是这样的。

public class TestController : Controller
{
        public class TestOut
    {
        public string InfoMessage { get; set; }
    }
    [HttpPost]
    [ValidateAntiForgeryToken]
    public JsonResult TestingOfHeader()
    {
        TestOut testOut = new TestOut()
        {
            InfoMessage = "I'm Here."
        };
        Response.Headers.Add("TempValue", "Test");
        return Json(testOut);
    }
}

从控制台运行,并按如下所示进行输出。

$.ajax({
            url: "/Dashboard/TestingOfHeader",
            type: 'POST',
            data: {
                __RequestVerificationToken: $('input[name="__RequestVerificationToken"]', $('#userHomePageDashboard')).val()
            },
            complete: function (results) {
                console.log("Response : " + results.responseText)
                }
            }
        );
Response : 

$.ajax({
            url: "/Dashboard/TestingOfHeader",
            type: 'POST',
            data: {
                __RequestVerificationToken: $('input[name="__RequestVerificationToken"]', $('#userHomePageDashboard')).val()
            },
            complete: function (results) {
                console.log("Response : " + results.responseText)
                }
            }
        );
Response : {"InfoMessage":"I'm Here."}

当我将响应标题的值设置为TempValue作为测试时,时间响应即将到来,而当TempValue作为“”]时,时间响应变为空白。

请帮助我解决问题。谢谢。

c# asp.net-core-webapi asp.net-core-2.2 response-headers
1个回答
0
投票

results.responseText仅返回您的身体部位。如果要获取标题,则必须用小写字母的键调用getResponseHeader函数。喜欢。results.getResponseHeader('tempvalue')

© www.soinside.com 2019 - 2024. All rights reserved.