MVC 4个Web API添加自定义的响应HTTP头 [英] mvc 4 web api add custom response http header
本文介绍了MVC 4个Web API添加自定义的响应HTTP头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们可以添加额外的HTTP响应头项目例如最近更新默认响应头的旁边?
Can we add the extra http response header item example "Last Updated" beside the default response header?
例如当我打电话(请求):
本地主机:12345 / API /
与头:
主持人:您当前位置:12345
......
那么API将与回复(响应)头:
HTTP / 1.1 200 OK
内容长度:XX
内容类型:XXX
最后更新:值和值与API函数生成
example when I call (Request):
localHost:12345/API/GetInfo
with header:
Host: localHost:12345
......
then the api will reply the header with(Response):
HTTP/1.1 200 OK
Content-Length: XX
Content-Type: XXX
Last-Update: The value and the value generate from the API function
推荐答案
您可以使用此code添加标题:
You can add header by using this code:
HttpContext.Current.Response.AppendHeader("Last-Update", value);
这篇关于MVC 4个Web API添加自定义的响应HTTP头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文