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


C# HttpContext.GetFeature方法代码示例

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


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

示例1: InspectStatusCode

 private bool InspectStatusCode(HttpContext context)
 {
     StatusCodeAction action;
     int statusCode = context.Response.StatusCode;
     if (options.StatusCodeActions.TryGetValue(statusCode, out action)
         && action == StatusCodeAction.ReplaceResponse)
     {
         context.GetFeature<BackupStreamFeature>().Replace = true;
         return action == StatusCodeAction.ReplaceResponse;
     }
     context.GetFeature<BackupStreamFeature>().Replace = false;
     return false;
 }
开发者ID:jchannon,项目名称:CustomStatusCodes,代码行数:13,代码来源:CustomStatusCodesMiddleware.cs

示例2: Invoke

        public Task Invoke(HttpContext context)
        {
            // Detect if an opaque upgrade is available. If so, add a websocket upgrade.
            var upgradeFeature = context.GetFeature<IHttpUpgradeFeature>();
            if (upgradeFeature != null)
            {
                if (_options.ReplaceFeature || context.GetFeature<IHttpWebSocketFeature>() == null)
                {
                    context.SetFeature<IHttpWebSocketFeature>(new UpgradeHandshake(context, upgradeFeature, _options));
                }
            }

            return _next(context);
        }
开发者ID:hitesh97,项目名称:WebSockets,代码行数:14,代码来源:WebSocketMiddleware.cs

示例3: Invoke

        public Task Invoke(HttpContext context)
        {
            // Check if there is a SendFile feature already present
            if (context.GetFeature<IHttpSendFileFeature>() == null)
            {
                context.SetFeature<IHttpSendFileFeature>(new SendFileWrapper(context.Response.Body, _logger));
            }

            return _next(context);
        }
开发者ID:RehanSaeed,项目名称:StaticFiles,代码行数:10,代码来源:SendFileMiddleware.cs

示例4: SendImageLink

 private Task SendImageLink(HttpContext context, string link)
 {
     context.Response.Body = context.GetFeature<BackupStreamFeature>().Body;
     context.Response.ContentType = "text/html";
     string body = string.Format("<html><body><img src=\"{0}\" /></body></html>",
         WebUtility.HtmlEncode(link));
     body += new string(' ', 512); // Padding to bypass IE's friendly error pages.
     context.Response.ContentLength = body.Length;
     return context.Response.WriteAsync(body);
 }
开发者ID:jchannon,项目名称:CustomStatusCodes,代码行数:10,代码来源:LinkedImagePageGenerator.cs

示例5: Invoke

        public async Task Invoke(HttpContext context)
        {
            var environment = (IApplicationEnvironment)context.RequestServices.GetService(typeof(IApplicationEnvironment));

            if (context.GetFeature<IHttpSendFileFeature>() == null)
            {
                var sendFile = new SendFileFallBack(context.Response.Body, environment.ApplicationBasePath);
                context.SetFeature<IHttpSendFileFeature>(sendFile);
            }

            await _next(context);
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:12,代码来源:SendFileMiddleware.cs

示例6: Invoke

        public async Task Invoke(HttpContext context)
        {
            var errorFeature = context.GetFeature<IErrorHandlerFeature>();

            if(errorFeature.Error != null)
            {
                _logger.LogCritical("A critical exception occurred.", errorFeature.Error);
            } else
            {
                _logger.LogCritical("There was an error...");
            }

            //IErrorHandlerFeature
            context.Response.StatusCode = 200;
            
            // we're going to "short-circuit" the pipeline
            await context.Response.WriteAsync("There was an error . But it was logged.");            
        }
开发者ID:rafsan,项目名称:Cancel,代码行数:18,代码来源:Startup.cs

示例7: RequestIdentifier

        private RequestIdentifier(HttpContext context)
        {
            _context = context;
            _feature = context.GetFeature<IHttpRequestIdentifierFeature>();

            if (_feature == null)
            {
                _feature = new HttpRequestIdentifierFeature()
                {
                    TraceIdentifier = Guid.NewGuid().ToString()
                };
                context.SetFeature(_feature);
                _addedFeature = true;
            }
            else if (string.IsNullOrEmpty(_feature.TraceIdentifier))
            {
                _originalIdentifierValue = _feature.TraceIdentifier;
                _feature.TraceIdentifier = Guid.NewGuid().ToString();
                _updatedIdentifier = true;
            }
        }
开发者ID:knnithyanand,项目名称:Diagnostics,代码行数:21,代码来源:RequestIdentifier.cs

示例8: Invoke

 public async Task Invoke(HttpContext context)
 {
     context.SetFeature<BackupStreamFeature>(new BackupStreamFeature() { Body = context.Response.Body });
     context.Response.Body = new StreamWrapper(context.Response.Body, InspectStatusCode, context);
     await _next.Invoke(context);
     
     StatusCodeAction action;
     int statusCode = context.Response.StatusCode;
     bool? replace = context.GetFeature<BackupStreamFeature>().Replace;
     if (!replace.HasValue)
     {
         // Never evaluated, no response sent yet.
         if (options.StatusCodeActions.TryGetValue(statusCode, out action)
             && action != StatusCodeAction.Ignore)
         {
             await options.ResponseGenerator(context);
         }
     }
     else if (replace.Value == true)
     {
         await options.ResponseGenerator(context);
     }
 }
开发者ID:jchannon,项目名称:CustomStatusCodes,代码行数:23,代码来源:CustomStatusCodesMiddleware.cs

示例9: GetRequestIdentifier

        private string GetRequestIdentifier(HttpContext httpContext)
        {
            var requestIdentifierFeature = httpContext.GetFeature<IHttpRequestIdentifierFeature>();
            if (requestIdentifierFeature == null)
            {
                requestIdentifierFeature = new HttpRequestIdentifierFeature()
                {
                    TraceIdentifier = Guid.NewGuid().ToString()
                };
                httpContext.SetFeature(requestIdentifierFeature);
            }

            return requestIdentifierFeature.TraceIdentifier;
        }
开发者ID:Kagamine,项目名称:Hosting,代码行数:14,代码来源:HostingEngine.cs

示例10: Invoke

 public async Task Invoke(HttpContext context)
 {
     var feature = context.GetFeature<IErrorHandlerFeature>();
     _logger.LogError("Error in Application", feature.Error);
     await WriteErrorResponseAsync(context, feature.Error);
 }
开发者ID:QuangDang212,项目名称:StorageApps,代码行数:6,代码来源:JsonErrorMiddleware.cs

示例11: IsSessionEnabled

 private static bool IsSessionEnabled(HttpContext context)
 {
     return context.GetFeature<ISessionFeature>() != null;
 }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:4,代码来源:SessionStateTempDataProvider.cs

示例12: ProcessNegotiationRequest

        private Task ProcessNegotiationRequest(HttpContext context)
        {
            // Total amount of time without a keep alive before the client should attempt to reconnect in seconds.
            var keepAliveTimeout = _options.Transports.KeepAliveTimeout();
            string connectionId = Guid.NewGuid().ToString("d");
            string connectionToken = connectionId + ':' + GetUserIdentity(context);

            var payload = new
            {
                Url = context.Request.LocalPath().Replace("/negotiate", ""),
                ConnectionToken = ProtectedData.Protect(connectionToken, Purposes.ConnectionToken),
                ConnectionId = connectionId,
                KeepAliveTimeout = keepAliveTimeout != null ? keepAliveTimeout.Value.TotalSeconds : (double?)null,
                DisconnectTimeout = _options.Transports.DisconnectTimeout.TotalSeconds,
                ConnectionTimeout = _options.Transports.LongPolling.PollTimeout.TotalSeconds,
                // TODO: Supports websockets
                TryWebSockets = _transportManager.SupportsTransport(WebSocketsTransportName) && context.GetFeature<IHttpWebSocketFeature>() != null,
                ProtocolVersion = _protocolResolver.Resolve(context.Request).ToString(),
                TransportConnectTimeout = _options.Transports.TransportConnectTimeout.TotalSeconds,
                LongPollDelay = _options.Transports.LongPolling.PollDelay.TotalSeconds
            };

            return SendJsonResponse(context, JsonSerializer.Stringify(payload));
        }
开发者ID:REALTOBIZ,项目名称:SignalR-Server,代码行数:24,代码来源:PersistentConnection.cs

示例13: OnInitializeTelemetry

        protected override void OnInitializeTelemetry(HttpContext platformContext, RequestTelemetry requestTelemetry, ITelemetry telemetry)
        {
            if (!string.IsNullOrEmpty(telemetry.Context.Location.Ip))
            {
                //already populated
                return;
            }

            if (string.IsNullOrEmpty(requestTelemetry.Context.Location.Ip))
            {
                string resultIp = null;
                foreach (var name in this.HeaderNames)
                {
                    var headerValue = platformContext.Request.Headers[name];
                    if (!string.IsNullOrEmpty(headerValue))
                    {
                        var ip = GetIpFromHeader(headerValue);
                        ip = CutPort(ip);
                        if (IsCorrectIpAddress(ip))
                        {
                            resultIp = ip;
                            break;
                        }
                    }
                }

                if (string.IsNullOrEmpty(resultIp))
                {
                    var connectionFeature = platformContext.GetFeature<IHttpConnectionFeature>();

                    if (connectionFeature != null)
                    {
                        resultIp = connectionFeature.RemoteIpAddress.ToString();
                    }
                }

                requestTelemetry.Context.Location.Ip = resultIp;
            }
            telemetry.Context.Location.Ip = requestTelemetry.Context.Location.Ip;
        }
开发者ID:hackathonvixion,项目名称:ApplicationInsights-aspnet5,代码行数:40,代码来源:ClientIpHeaderTelemetryInitializer.cs


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