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


C# OwinContext.Set方法代码示例

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


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

示例1: Invoke

 public async Task Invoke(IDictionary<string, object> env)
 {
     var context = new OwinContext(env);
     var session = _kernel.Get<IDocumentStore>().OpenSession();
     _kernel.Bind<IDocumentSession>()
         .ToConstant(session)
          .InSingletonScope();
     context.Set("documentSession", session);
     await _next(env);
 }
开发者ID:joshuadeanhall,项目名称:EmailReceiverTwo,代码行数:10,代码来源:RavenSessionHandler.cs

示例2: CreateOwinContext

        public static IOwinContext CreateOwinContext()
        {
            var ctx = new OwinContext();

            ctx.Request.SetUrl("http://nuget.local/");

            // Fill in some values that cause exceptions if not present
            ctx.Set<Action<Action<object>, object>>("server.OnSendingHeaders", (_, __) => { });

            return ctx;
        }
开发者ID:ZhiYuanHuang,项目名称:NuGetGallery,代码行数:11,代码来源:Fakes.cs

示例3: Invoke

        public async Task Invoke(IDictionary<string, object> env)
        {
            Guid correlationToken;
            var owinContext = new OwinContext(env);
            if (!(owinContext.Request.Headers["Correlation-Token"] != null
                && Guid.TryParse(owinContext.Request.Headers["Correlation-Token"], out correlationToken)))
                correlationToken = Guid.NewGuid();

            owinContext.Set("correlationToken", correlationToken.ToString());
            using (LogContext.PushProperty("CorrelationToken", correlationToken.ToString()))
                await next(env).ConfigureAwait(false);
        }
开发者ID:madhon,项目名称:NancyHelloWorld,代码行数:12,代码来源:CorrelationToken.cs

示例4: Invoke

        /// <summary>
        /// Adds the sendfile.SendAsync Func to the request environment, if not already present.
        /// </summary>
        /// <param name="environment">OWIN environment dictionary which stores state information about the request, response and relevant server state.</param>
        /// <returns></returns>
        public Task Invoke(IDictionary<string, object> environment)
        {
            IOwinContext context = new OwinContext(environment);

            // Check if there is a SendFile delegate already presents
            if (context.Get<object>(Constants.SendFileAsyncKey) as SendFileFunc == null)
            {
                context.Set<SendFileFunc>(Constants.SendFileAsyncKey, new SendFileFunc(new SendFileWrapper(context.Response.Body).SendAsync));
            }

            return _next(environment);
        }
开发者ID:Kstal,项目名称:Microsoft.Owin,代码行数:17,代码来源:SendFileMiddleware.cs

示例5: Invoke

        public async Task Invoke(IDictionary<string, object> env)
        {
            var context = new OwinContext(env);

            // this creates a per-request, disposable scope
            using (var scope = _container.BeginLifetimeScope(b =>
            {
                // this makes owin context resolvable in the scope
                b.RegisterInstance(context).As<IOwinContext>();
            }))
            {
                // this makes scope available for downstream frameworks
                context.Set<ILifetimeScope>("idsrv:WsFedAutofacScope", scope);
                await _next(env);
            }
        }
开发者ID:thereverand,项目名称:IdentityServer3.WsFederation,代码行数:16,代码来源:AutofacContainerMiddleware.cs

示例6: CertificateAndClientIdPresent

        public async Task CertificateAndClientIdPresent()
        {
            var parser = new X509CertificateSecretParser();
            var context = new OwinContext();

            var body = "client_id=client";
            context.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes(body));

            var cert = TestCert.Load();
            context.Set("ssl.ClientCertificate", cert);

            var secret = await parser.ParseAsync(context.Environment);

            secret.Type.Should().Be(Constants.ParsedSecretTypes.X509Certificate);
            secret.Id.Should().Be("client");
            secret.Credential.Should().NotBeNull();
            secret.Credential.ShouldBeEquivalentTo(cert);
        }
开发者ID:Rolosoft,项目名称:IdentityServer3,代码行数:18,代码来源:X509CertificateSecretParsing.cs

示例7: AddsAutofacDependencyScopeToHttpRequestMessage

        public async void AddsAutofacDependencyScopeToHttpRequestMessage()
        {
            var request = new HttpRequestMessage();
            var context = new OwinContext();
            request.Properties.Add("MS_OwinContext", context);

            var container = new ContainerBuilder().Build();
            context.Set(Constants.OwinLifetimeScopeKey, container);

            var fakeHandler = new FakeInnerHandler {Message = new HttpResponseMessage(HttpStatusCode.OK)};
            var handler = new DependencyScopeHandler {InnerHandler = fakeHandler};
            var invoker = new HttpMessageInvoker(handler);
            await invoker.SendAsync(request, new CancellationToken());

            var scope = (AutofacWebApiDependencyScope)request.Properties[HttpPropertyKeys.DependencyScope];

            Assert.That(scope.LifetimeScope, Is.EqualTo(container));
        }
开发者ID:RoymanJing,项目名称:Autofac,代码行数:18,代码来源:DependencyScopeHandlerFixture.cs

示例8: Invoke

        /// <summary>
        /// Invokes the middleware.
        /// </summary>
        /// <param name="environment">The environment.</param>
        /// <returns></returns>
        public async Task Invoke(IDictionary<string, object> environment)
        {
            var context = new OwinContext(environment);

            var token = await GetTokenAsync(context);

            if (token == null)
            {
                await _next(environment);
                return;
            }

            context.Set("idsrv:tokenvalidation:token", token);

            // seems to be a JWT
            if (token.Contains('.'))
            {
                // see if local validation is setup
                if (_localValidationFunc != null)
                {
                    await _localValidationFunc(environment);
                    return;
                }
                // otherwise use validation endpoint
                if (_endpointValidationFunc != null)
                {
                    await _endpointValidationFunc(environment);
                    return;
                }
            }
            else
            {
                // use validation endpoint
                if (_endpointValidationFunc != null)
                {
                    await _endpointValidationFunc(environment);
                    return;
                }
            }

            await _next(environment);
        }
开发者ID:ahmad2x4,项目名称:IdentityServer3.AccessTokenValidation,代码行数:47,代码来源:IdentityServerBearerTokenValidationMiddleware.cs

示例9: CreateOwinContext

        public static IOwinContext CreateOwinContext(IdentityServerOptions options, IClientStore clients, IUserService users)
        {
            options.Factory = options.Factory ?? new IdentityServerServiceFactory();
            if (users != null)
            {
                options.Factory.UserService = new Registration<IUserService>(users);
            }
            if (options.Factory.UserService == null)
            {
                options.Factory.UseInMemoryUsers(new List<InMemoryUser>());
            }

            if (clients != null)
            {
                options.Factory.ClientStore = new Registration<IClientStore>(clients);
            }
            if (options.Factory.ClientStore == null)
            {
                options.Factory.UseInMemoryClients(new List<Client>());
            }

            if (options.Factory.ScopeStore == null)
            {
                options.Factory.UseInMemoryScopes(new List<Scope>());
            }

            var container = AutofacConfig.Configure(options);

            var context = new OwinContext();
            context.Set(Autofac.Integration.Owin.Constants.OwinLifetimeScopeKey, container);

            return context;
        }
开发者ID:henryng24,项目名称:IdentityServer3,代码行数:33,代码来源:Factory.cs

示例10: RequestState

            internal RequestState(HttpRequestMessage request, CancellationToken cancellationToken)
            {
                _request = request;
                _responseTcs = new TaskCompletionSource<HttpResponseMessage>();
                _sendingHeaders = () => { };

                if (request.RequestUri.IsDefaultPort)
                {
                    request.Headers.Host = request.RequestUri.Host;
                }
                else
                {
                    request.Headers.Host = request.RequestUri.GetComponents(UriComponents.HostAndPort, UriFormat.UriEscaped);
                }

                OwinContext = new OwinContext();
                OwinContext.Set("owin.Version", "1.0");
                IOwinRequest owinRequest = OwinContext.Request;
                owinRequest.Protocol = "HTTP/" + request.Version.ToString(2);
                owinRequest.Scheme = request.RequestUri.Scheme;
                owinRequest.Method = request.Method.ToString();
                owinRequest.Path = PathString.FromUriComponent(request.RequestUri);
                owinRequest.PathBase = PathString.Empty;
                owinRequest.QueryString = QueryString.FromUriComponent(request.RequestUri);
                owinRequest.CallCancelled = cancellationToken;
                owinRequest.Set<Action<Action<object>, object>>("server.OnSendingHeaders", (callback, state) =>
                {
                    var prior = _sendingHeaders;
                    _sendingHeaders = () =>
                    {
                        prior();
                        callback(state);
                    };
                });

                foreach (var header in request.Headers)
                {
                    owinRequest.Headers.AppendValues(header.Key, header.Value.ToArray());
                }
                HttpContent requestContent = request.Content;
                if (requestContent != null)
                {
                    foreach (var header in request.Content.Headers)
                    {
                        owinRequest.Headers.AppendValues(header.Key, header.Value.ToArray());
                    }
                }

                _responseStream = new ResponseStream(CompleteResponse);
                OwinContext.Response.Body = _responseStream;
                OwinContext.Response.StatusCode = 200;
            }
开发者ID:Kstal,项目名称:Microsoft.Owin,代码行数:52,代码来源:OwinClientHandler.cs


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