我正在处理一个场景,我必须将 header 添加到响应 header 。
我添加了一个像这样的响应头:-
HttpContext.Current.Response.AddHeader("key1", "value1")
在一些功能流程之后,我需要将值添加到相同的“key1”:HttpContext.Current.Reponse.AddHeader("key1, "value2")
因此响应 header 中的值如下所示:- key1 : value1, value2
我想避免将 value2 添加到同一关键字 key1。
如何解决这个问题?
我试过:-
If HttpContext.Current.Response.Headers("key1") Then
HttpContext.Current.Reponse.AddHeader("key1, "value2")
EndIf
但我收到错误:此操作需要 IIS 集成管道模式 在 HttpContext.Current.Response.Headers("key1")
我正在运行 IIS6。 这http://forums.asp.net/post/2676139.aspx说如果不是 IIS7,它就不起作用
如果我可以在 IIS6 中做到这一点,请帮忙。谢谢,
最佳答案
您可以使用此行检查它是否有 key
HttpContext.Current.Response.Headers.HasKeys()
所以在你的例子中你会这样做
If Not HttpContext.Current.Response.Headers.HasKeys() Then
HttpContext.Current.Reponse.AddHeader("key1, "value2")
EndIf
希望对你有帮助
关于c# - 如何检查 HttpContext.Current.Response 是否有现有的 Header?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11102130/