嗨,我正在开发API的使用Web API 2.我知道如何使用HttpResponseMessage
添加标题。现在我正在使用IHttpActionResult
。如何在Web API 2的IHttpActionResult中添加头文件?
下面是我的样本当前代码。
return Content(HttpStatusCode.OK, LoginResponse);
如何在我返回内容时添加标题?
每当我使用HttpResponseMessage
我将有请求对象,我可以添加标题。
下面的代码我试过在HttpResponseMessage
。
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
response.Headers.AddCookies(new[] { cookie });
return response;
在这种情况下,我可以添加标题值?
HttpContext.Current.Response.AppendHeader("Some-Header", value);
或本
response.Headers.Add("Some-Header", value);
谢谢PECO。它正在工作。我还没有理解你在上面的代码中做了什么!我可以知道上面解释的是什么吗?谢谢! –
下面是代表的简短说明:https://www.codementor.io/aydinadn/delegates-func-act-in-c-sharp-du107s5mj这里是一个装饰模式的例子:https:// assist- software.net/blog/implementation-decorator-pattern-c希望它有帮助! – peco