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


C# HttpRequestMessage.SetOwinContext方法代码示例

本文整理汇总了C#中System.Net.Http.HttpRequestMessage.SetOwinContext方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestMessage.SetOwinContext方法的具体用法?C# HttpRequestMessage.SetOwinContext怎么用?C# HttpRequestMessage.SetOwinContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Http.HttpRequestMessage的用法示例。


在下文中一共展示了HttpRequestMessage.SetOwinContext方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendAsync

 protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
 {
     HttpRequestContext context = request.GetRequestContext();
     context.Principal = Principal;
     request.SetOwinContext(this.OwinContext);
     return base.SendAsync(request, cancellationToken);
 }
开发者ID:andreychizhov,项目名称:microsoft-aspnet-samples,代码行数:7,代码来源:RequestContextHandler.cs

示例2: GetOwinContext_ReturnsSetContextInstance

        public void GetOwinContext_ReturnsSetContextInstance()
        {
            // Arrange
            var request = new HttpRequestMessage();
            var context = new OwinContext();
            request.SetOwinContext(context);

            // Act & Asert
            Assert.Same(context, request.GetOwinContext());
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:10,代码来源:OwinHttpRequestMessageExtensionsTest.cs

示例3: SetOwinContext_RemovesOwinEnvironmentProperty_WhenPresent

        public void SetOwinContext_RemovesOwinEnvironmentProperty_WhenPresent()
        {
            // Arrange
            using (HttpRequestMessage request = new HttpRequestMessage())
            {
                var environment = new Dictionary<string, object>();
                request.Properties.Add("MS_OwinEnvironment", environment);
                var context = new OwinContext();

                // Act
                request.SetOwinContext(context);

                // Assert
                Assert.False(request.Properties.ContainsKey("MS_OwinEnvironment"));
            }
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:16,代码来源:OwinHttpRequestMessageExtensionsTest.cs

示例4: MapRequestProperties

        private static void MapRequestProperties(HttpRequestMessage request, IOwinContext context)
        {
            // Set the OWIN context on the request
            request.SetOwinContext(context);

            // Set the a request context on the request that lazily populates each property.
            HttpRequestContext requestContext = new OwinHttpRequestContext(context, request);
            request.SetRequestContext(requestContext);
        }
开发者ID:khorchani,项目名称:aspnetwebstack,代码行数:9,代码来源:HttpMessageHandlerAdapter.cs

示例5: CreateRequestMessage

        private HttpRequestMessage CreateRequestMessage(ClaimsPrincipal user, bool isCompressed, bool isJson, string charset = "utf-8") {
            var request = new HttpRequestMessage();

            var context = new OwinContext();
            context.Request.User = Thread.CurrentPrincipal = user;
            request.SetOwinContext(context);
            request.SetConfiguration(new HttpConfiguration());
            request.Content = new HttpMessageContent(new HttpRequestMessage(HttpMethod.Post, "/api/v2/events"));
            if (isCompressed)
                request.Content.Headers.ContentEncoding.Add("gzip");
            request.Content.Headers.ContentType.MediaType = isJson ? "application/json" : "text/plain";
            request.Content.Headers.ContentType.CharSet = charset;

            return request;
        }
开发者ID:rpotalara,项目名称:Exceptionless,代码行数:15,代码来源:EventControllerTests.cs

示例6: CreateRequestWithOwinContextAndRequestContext

 private static HttpRequestMessage CreateRequestWithOwinContextAndRequestContext(IOwinContext context)
 {
     HttpRequestMessage request = new HttpRequestMessage();
     request.SetOwinContext(context);
     request.SetRequestContext(new HttpRequestContext());
     return request;
 }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:7,代码来源:PassiveAuthenticationMessageHandlerTest.cs

示例7: SendAsync_SetsRequestContextPrincipalToAnonymous_BeforeCallingInnerHandler

        public void SendAsync_SetsRequestContextPrincipalToAnonymous_BeforeCallingInnerHandler()
        {
            // Arrange
            IPrincipal requestContextPrincipal = null;
            Mock<HttpRequestContext> requestContextMock = new Mock<HttpRequestContext>(MockBehavior.Strict);
            requestContextMock
                .SetupSet(c => c.Principal = It.IsAny<IPrincipal>())
                .Callback<IPrincipal>((value) => requestContextPrincipal = value);
            IPrincipal principalBeforeInnerHandler = null;
            HttpMessageHandler inner = new LambdaHttpMessageHandler((ignore1, ignore2) =>
            {
                principalBeforeInnerHandler = requestContextPrincipal;
                return Task.FromResult<HttpResponseMessage>(null);
            });
            HttpMessageHandler handler = CreateProductUnderTest(inner);
            IOwinContext context = CreateOwinContext();

            using (HttpRequestMessage request = new HttpRequestMessage())
            {
                request.SetOwinContext(context);
                request.SetRequestContext(requestContextMock.Object);

                // Act
                HttpResponseMessage ignore = handler.SendAsync(request, CancellationToken.None).Result;
            }

            // Assert
            Assert.NotNull(principalBeforeInnerHandler);
            IIdentity identity = principalBeforeInnerHandler.Identity;
            Assert.NotNull(identity);
            Assert.False(identity.IsAuthenticated);
            Assert.Null(identity.Name);
            Assert.Null(identity.AuthenticationType);
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:34,代码来源:PassiveAuthenticationMessageHandlerTest.cs

示例8: MapRequestProperties

        private static void MapRequestProperties(HttpRequestMessage request, IOwinContext context)
        {
            // Set the OWIN context on the request
            request.SetOwinContext(context);

            // Set the virtual path root for link resolution and link generation to work
            // OWIN spec requires request path base to be either the empty string or start with "/"
            string requestPathBase = context.Request.PathBase;
            request.SetVirtualPathRoot(String.IsNullOrEmpty(requestPathBase) ? "/" : requestPathBase);

            // Set a delegate to get the client certificate
            request.Properties[HttpPropertyKeys.RetrieveClientCertificateDelegateKey] = new Func<HttpRequestMessage, X509Certificate2>(
                req => context.Get<X509Certificate2>(OwinConstants.ClientCertifiateKey));

            // Set a lazily-evaluated way of determining whether the request is local or not
            Lazy<bool> isLocal = new Lazy<bool>(() => context.Get<bool>(OwinConstants.IsLocalKey), isThreadSafe: false);
            request.Properties[HttpPropertyKeys.IsLocalKey] = isLocal;
        }
开发者ID:RhysC,项目名称:aspnetwebstack,代码行数:18,代码来源:HttpMessageHandlerAdapter.cs

示例9: CreateRequest

 private static HttpRequestMessage CreateRequest(IOwinContext owinContext)
 {
     HttpRequestMessage request = new HttpRequestMessage();
     request.SetOwinContext(owinContext);
     return request;
 }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:6,代码来源:HostAuthenticationFilterTest.cs

示例10: SendAsync

 protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
 {
     request.SetOwinContext(new OwinContext());
     return base.SendAsync(request, cancellationToken);
 }
开发者ID:RossMerr,项目名称:azure-mobile-apps-net-server,代码行数:5,代码来源:HostMockHandler.cs

示例11: GetOwinEnvironment_ReturnsSetContextEnvironmentInstance

        public void GetOwinEnvironment_ReturnsSetContextEnvironmentInstance()
        {
            // Arrange
            var request = new HttpRequestMessage();
            var environment = new Dictionary<string, object>();
            var context = new OwinContext(environment);
            request.SetOwinContext(context);

            // Act & Assert
            Assert.Same(environment, request.GetOwinEnvironment());
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:11,代码来源:OwinHttpRequestMessageExtensionsTest.cs


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