本文整理汇总了C#中System.Net.Http.HttpResponseMessage.WriteCorsHeaders方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseMessage.WriteCorsHeaders方法的具体用法?C# HttpResponseMessage.WriteCorsHeaders怎么用?C# HttpResponseMessage.WriteCorsHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpResponseMessage
的用法示例。
在下文中一共展示了HttpResponseMessage.WriteCorsHeaders方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteCorsHeaders_NullCorsResult_Throws
public void WriteCorsHeaders_NullCorsResult_Throws()
{
HttpResponseMessage response = new HttpResponseMessage();
Assert.ThrowsArgumentNull(() =>
response.WriteCorsHeaders(null),
"corsResult");
}
示例2: WriteCorsHeaders_WritesAllowExposedHeaders
public void WriteCorsHeaders_WritesAllowExposedHeaders()
{
HttpResponseMessage response = new HttpResponseMessage();
CorsResult corsResult = new CorsResult();
corsResult.AllowedExposedHeaders.Add("baz");
response.WriteCorsHeaders(corsResult);
HttpResponseHeaders headers = response.Headers;
Assert.Equal(1, headers.Count());
string[] exposedHeaders = headers.GetValues("Access-Control-Expose-Headers").FirstOrDefault().Split(',');
Assert.Contains("baz", exposedHeaders);
}
示例3: WriteCorsHeaders_WritesAllowMethods
public void WriteCorsHeaders_WritesAllowMethods()
{
HttpResponseMessage response = new HttpResponseMessage();
CorsResult corsResult = new CorsResult();
corsResult.AllowedMethods.Add("DELETE");
corsResult.AllowedMethods.Add("PUT");
response.WriteCorsHeaders(corsResult);
HttpResponseHeaders headers = response.Headers;
Assert.Equal(1, headers.Count());
string[] allowMethods = headers.GetValues("Access-Control-Allow-Methods").FirstOrDefault().Split(',');
Assert.Contains("DELETE", allowMethods);
Assert.Contains("PUT", allowMethods);
}
示例4: WriteCorsHeaders_WritesAllowCredentials
public void WriteCorsHeaders_WritesAllowCredentials()
{
HttpResponseMessage response = new HttpResponseMessage();
CorsResult corsResult = new CorsResult
{
SupportsCredentials = true
};
response.WriteCorsHeaders(corsResult);
HttpResponseHeaders headers = response.Headers;
Assert.Equal(1, headers.Count());
Assert.Equal("true", headers.GetValues("Access-Control-Allow-Credentials").FirstOrDefault());
}
示例5: WriteCorsHeaders_EmptyCorsResult_EmptyHeaders
public void WriteCorsHeaders_EmptyCorsResult_EmptyHeaders()
{
HttpResponseMessage response = new HttpResponseMessage();
response.WriteCorsHeaders(new CorsResult());
Assert.Empty(response.Headers);
}
示例6: WriteCorsHeaders_WritesPreflightMaxAge
public void WriteCorsHeaders_WritesPreflightMaxAge()
{
HttpResponseMessage response = new HttpResponseMessage();
CorsResult corsResult = new CorsResult
{
PreflightMaxAge = 10
};
response.WriteCorsHeaders(corsResult);
HttpResponseHeaders headers = response.Headers;
Assert.Equal(1, headers.Count());
Assert.Equal("10", headers.GetValues("Access-Control-Max-Age").FirstOrDefault());
}
示例7: WriteCorsHeaders_WritesAllowOrigin
public void WriteCorsHeaders_WritesAllowOrigin()
{
HttpResponseMessage response = new HttpResponseMessage();
CorsResult corsResult = new CorsResult
{
AllowedOrigin = "*"
};
response.WriteCorsHeaders(corsResult);
HttpResponseHeaders headers = response.Headers;
Assert.Equal(1, headers.Count());
Assert.Equal("*", headers.GetValues("Access-Control-Allow-Origin").FirstOrDefault());
}