當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。