0
我一直在試圖添加一個自定義頭的值到傳出響應消息。每個用戶請求的值都不相同。Restful WCF添加消息頭到傳出響應
但是我不能用下面的代碼添加具有價值的標題:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service : IMyService
{
public string CommandHandler()
{
string s = "test";
WebOperationContext.Current.OutgoingResponse.Headers.Add("testheader", "123456");
return s;
}
}
如果我下面的代碼添加到global.asax
,它的工作原理,但testheader
總是123
,我不能改變的值。
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET");
HttpContext.Current.Response.AddHeader("testheader", "123");
HttpContext.Current.Response.End();
}
}
現在它工作!非常感謝你 ! – Coach