本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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));
}
示例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;
}
示例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;
}