当前位置: 首页>>代码示例>>C#>>正文


C# HttpResponseMessage.WriteCorsHeaders方法代码示例

本文整理汇总了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");
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:8,代码来源:CorsHttpResponseMessageExtensionsTest.cs

示例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);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:13,代码来源:CorsHttpResponseMessageExtensionsTest.cs

示例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);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:15,代码来源:CorsHttpResponseMessageExtensionsTest.cs

示例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());
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:14,代码来源:CorsHttpResponseMessageExtensionsTest.cs

示例5: WriteCorsHeaders_EmptyCorsResult_EmptyHeaders

 public void WriteCorsHeaders_EmptyCorsResult_EmptyHeaders()
 {
     HttpResponseMessage response = new HttpResponseMessage();
     response.WriteCorsHeaders(new CorsResult());
     Assert.Empty(response.Headers);
 }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:6,代码来源:CorsHttpResponseMessageExtensionsTest.cs

示例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());
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:14,代码来源:CorsHttpResponseMessageExtensionsTest.cs

示例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());
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:14,代码来源:CorsHttpResponseMessageExtensionsTest.cs


注:本文中的System.Net.Http.HttpResponseMessage.WriteCorsHeaders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。