本文整理汇总了C#中System.Net.Http.HttpRequestMessage.GetOwinContext方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestMessage.GetOwinContext方法的具体用法?C# HttpRequestMessage.GetOwinContext怎么用?C# HttpRequestMessage.GetOwinContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpRequestMessage
的用法示例。
在下文中一共展示了HttpRequestMessage.GetOwinContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleRequest
/// <summary>Handles the request.</summary>
/// <param name="request">The request.</param>
/// <param name="cancellationToken">A cancellation token to cancel operation.</param>
/// <returns>A Task<HttpResponseMessage></returns>
public override Task<HttpRequestMessage> HandleRequest(HttpRequestMessage request, CancellationToken cancellationToken)
{
request.GetOwinContext().Response.OnSendingHeaders(
response =>
{
((IOwinResponse)response).Environment["HeadersWritten"] = true;
},
request.GetOwinContext().Response);
return base.HandleRequest(request, cancellationToken);
}
开发者ID:SneakyMax,项目名称:Microsoft.AspNet.WebApi.MessageHandlers.Compression,代码行数:15,代码来源:OwinServerCompressionHandler.cs
示例2: AuthAndUserManager
public AuthAndUserManager(HttpRequestMessage request)
{
if (request == null)
{
throw new ArgumentException("Http Request must exist in order to use AuthAndUserManager", "request");
}
_userManager = request.GetOwinContext().GetUserManager<ApplicationUserManager>();
_signInManager = request.GetOwinContext().Get<ApplicationSignInManager>();
_roleManager = request.GetOwinContext().Get<ApplicationRoleManager>();
_authentication = request.GetOwinContext().Authentication;
Logger = LoggerFactory.GetLogger(GetType());
}
示例3: SendAsync
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
var context = request.GetRequestContext();
var user = context.Principal.Identity;
if (!user.IsAuthenticated)
{
IdentityResult result;
ApplicationUserManager userManager = request.GetOwinContext().GetUserManager<ApplicationUserManager>();
var appUser = await userManager.FindByNameAsync(DummyName);
if (appUser == null)
{
appUser = new ApplicationUser() { UserName = DummyName, Email = DummyName };
result = await userManager.CreateAsync(appUser);
}
ClaimsIdentity oAuthIdentity = await appUser.GenerateUserIdentityAsync(userManager, OAuthDefaults.AuthenticationType);
context.Principal = new ClaimsPrincipal(oAuthIdentity);
}
return await base.SendAsync(request, cancellationToken);
}
示例4: SendAsync
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
// Get the OWIN request
var owinRequest = request.GetOwinContext();
if (owinRequest == null)
throw new Exception("OWIN Context is null.");
// Spin up logging
var logger = LogManager.GetLogger("uManage");
logger.Debug("{{ \"apiRequest\": {{ \"request\": \"{0} {1}\", \"user\": \"{2}\", \"ipAddress\": \"{3}\" }}}}",
request.Method.Method,
request.RequestUri.PathAndQuery.ToLower(),
owinRequest.Authentication.User.Identity.Name.ToLower(),
owinRequest.Request.RemoteIpAddress);
// Time the request/process time for logging purposes
var stopwatch = Stopwatch.StartNew();
// Run the request
var response = await base.SendAsync(request, cancellationToken);
// Stop the stopwatch... it's the final countdown!!!
stopwatch.Stop();
// Log the request complete time and time taken
logger.Debug("{{ \"apiRequestComplete\": {{ \"request\": \"{0} {1}\", \"user\": \"{2}\", \"ipAddress\": \"{3}\", \"timeTaken\": \"{4}ms\" }}}}",
request.Method.Method,
request.RequestUri.PathAndQuery.ToLower(),
owinRequest.Authentication.User.Identity.Name.ToLower(),
owinRequest.Request.RemoteIpAddress,
stopwatch.ElapsedMilliseconds);
return response;
}
示例5: SendAsync
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
CancellationToken cancellationToken)
{
var owinContext = request.GetOwinContext();
request.Properties.Add(OwinHandlerBridgeResponse, owinContext.Response.ToHttpResponseMessage());
return _invoker.SendAsync(request, cancellationToken);
}
示例6: GetClientIpAddressFromHttpContextOrWcfSelfHost
// http://www.strathweb.com/2013/05/retrieving-the-clients-ip-address-in-asp-net-web-api/
public static string GetClientIpAddressFromHttpContextOrWcfSelfHost(HttpRequestMessage request)
{
request.GetOwinContext();
const string HttpContext = "MS_HttpContext";
const string RemoteEndpointMessage = "System.ServiceModel.Channels.RemoteEndpointMessageProperty";
if (request.Properties.ContainsKey(HttpContext))
{
dynamic ctx = request.Properties[HttpContext];
if (ctx != null)
{
return ctx.Request.UserHostAddress;
}
}
if (request.Properties.ContainsKey(RemoteEndpointMessage))
{
dynamic remoteEndpoint = request.Properties[RemoteEndpointMessage];
if (remoteEndpoint != null)
{
return remoteEndpoint.Address;
}
}
return null;
}
示例7: SendAsync
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var reqLog = new
{
Method = request.Method,
Url = request.RequestUri.AbsoluteUri,
Headers = request.Headers,
Body = await request.GetOwinContext().Request.ReadBodyAsStringAsync()
};
Logger.DebugFormat("HTTP Request\n{0}", LogSerializer.Serialize(reqLog));
var response = await base.SendAsync(request, cancellationToken);
string body = "";
if (response.Content != null)
{
body = await response.Content.ReadAsStringAsync();
}
var respLog = new
{
StatusCode = response.StatusCode,
Headers = response.Headers,
Body = body
};
Logger.DebugFormat("HTTP Response\n{0}", LogSerializer.Serialize(respLog));
return response;
}
示例8: EmbeddedHtmlResult
public EmbeddedHtmlResult(HttpRequestMessage request, string file, IdentityAdminOptions adminOptions)
{
var pathbase = request.GetOwinContext().Request.PathBase;
this.path = pathbase.Value;
this.file = file;
this.authorization_endpoint = pathbase + Constants.AuthorizePath;
this._adminOptions = adminOptions;
}
示例9: EmbeddedHtmlResult
public EmbeddedHtmlResult(HttpRequestMessage request, string file, SecurityConfiguration securityConfiguration)
{
var pathbase = request.GetOwinContext().Request.PathBase;
this.path = pathbase.Value;
this.file = file;
this.authorization_endpoint = pathbase + Constants.AuthorizePath;
this.securityConfiguration = securityConfiguration;
}
示例10: SendAsync
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var DependencyScope = request.GetOwinContext().Get<IDependencyScope>();
if (DependencyScope != null)
{
request.Properties[HttpPropertyKeys.DependencyScope] = DependencyScope;
}
return base.SendAsync(request, cancellationToken);
}
示例11: EmbeddedHtmlResult
public EmbeddedHtmlResult(HttpRequestMessage request, string file, OAuth2Configuration oauthConfig = null)
{
this.path = request.GetOwinContext().Request.PathBase.Value;
this.file = file;
this.oauthConfig = oauthConfig;
if (oauthConfig != null && oauthConfig.AutomaticallyRenewToken)
{
this.frameCallbackUrl = request.GetUrlHelper().Link(Constants.RouteNames.OAuthFrameCallback, null);
}
}
示例12: 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());
}
示例13: SendAsync
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var owin = request.GetOwinContext();
var scope = owin.Get<ILifetimeScope>("idsrv:AutofacScope");
if (scope != null)
{
request.Properties[HttpPropertyKeys.DependencyScope] = new AutofacScope(scope);
}
return base.SendAsync(request, cancellationToken);
}
示例14: SendAsync
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var owinContext = request.GetOwinContext();
if (owinContext != null)
{
var scopedContainer = owinContext.GetDryIocScopedContainer();
if (scopedContainer != null) // Use existing OWIN ScopeContainer for WebApi dependency resolver
request.Properties[HttpPropertyKeys.DependencyScope] = new DryIocDependencyScope(scopedContainer);
}
return base.SendAsync(request, cancellationToken);
}
示例15: GetODataPayloadSerializer
public override ODataSerializer GetODataPayloadSerializer(IEdmModel model, Type type, HttpRequestMessage request)
{
var serializer = base.GetODataPayloadSerializer(model, type, request);
if (serializer == null)
{
var response = request.GetOwinContext().Response;
response.OnSendingHeaders(state =>
{
((IOwinResponse)state).StatusCode = (int)HttpStatusCode.NotFound;
}, response);
return _nullEntityTypeSerializer;
}
return serializer;
}