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


C# HttpRequestMessage.GetOwinContext方法代码示例

本文整理汇总了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&lt;HttpResponseMessage&gt;</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());
 }
开发者ID:jarrhead777,项目名称:Cattle360,代码行数:12,代码来源:AuthAndUserManager.cs

示例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);
        }
开发者ID:smithyhammer,项目名称:Altostratus,代码行数:25,代码来源:DummyUserHandler.cs

示例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;
        }
开发者ID:jelkinsiv,项目名称:uManage,代码行数:34,代码来源:ApiLoggingHandler.cs

示例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);
 }
开发者ID:yyf919,项目名称:CacheCow,代码行数:7,代码来源:OwinHandlerBridge.cs

示例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;
        }
开发者ID:pmhsfelix,项目名称:ndc-london-13-web-api,代码行数:26,代码来源:IpAddressParameterBinding.cs

示例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;
        }
开发者ID:nheijminkccv,项目名称:IdentityServer3,代码行数:32,代码来源:RequestResponseLogger.cs

示例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;
 }
开发者ID:IdentityServer,项目名称:IdentityServer3.Admin,代码行数:8,代码来源:EmbeddedHtmlResult.cs

示例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;
 }
开发者ID:Hzinsp,项目名称:IdentityManager,代码行数:8,代码来源:EmbeddedHtmlResult.cs

示例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);
 }
开发者ID:charla-n,项目名称:ManahostManager,代码行数:9,代码来源:HttpServerResolver.cs

示例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);
     }
 }
开发者ID:krunalm,项目名称:Thinktecture.IdentityManager,代码行数:10,代码来源:EmbeddedHtmlResult.cs

示例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());
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:10,代码来源:OwinHttpRequestMessageExtensionsTest.cs

示例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);
        }
开发者ID:kphutt,项目名称:Thinktecture.IdentityServer.v3,代码行数:11,代码来源:KatanaDependencyResolver.cs

示例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);
        }
开发者ID:PowerDMS,项目名称:Owin.Scim,代码行数:12,代码来源:DryIocWebApiOwin.cs

示例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;
 }
开发者ID:MCornel,项目名称:OWIN_ODATA_ORDERS_API,代码行数:14,代码来源:NullSerializerProvider.cs


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