本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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.");
}
示例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;
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例11: IsSessionEnabled
private static bool IsSessionEnabled(HttpContext context)
{
return context.GetFeature<ISessionFeature>() != null;
}
示例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));
}
示例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