本文整理匯總了C#中System.Net.Http.HttpRequestMessage.GetActionDescriptor方法的典型用法代碼示例。如果您正苦於以下問題:C# HttpRequestMessage.GetActionDescriptor方法的具體用法?C# HttpRequestMessage.GetActionDescriptor怎麽用?C# HttpRequestMessage.GetActionDescriptor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Net.Http.HttpRequestMessage
的用法示例。
在下文中一共展示了HttpRequestMessage.GetActionDescriptor方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: WithIsIncomingRequestBasedOn
private static void WithIsIncomingRequestBasedOn(this Telemetry telemetry, HttpRequestMessage request)
{
if (request.GetActionDescriptor() != null)
{
telemetry.IsIncomingRequest(true);
}
}
示例2: WrapResultIfNeeded
protected virtual void WrapResultIfNeeded(HttpRequestMessage request, HttpResponseMessage response)
{
if (!response.IsSuccessStatusCode)
{
return;
}
if (_configuration.SetNoCacheForAllResponses)
{
//Based on http://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers
response.Headers.CacheControl = new CacheControlHeaderValue
{
NoCache = true,
NoStore = true,
MaxAge = TimeSpan.Zero,
MustRevalidate = true
};
}
var wrapAttr = HttpActionDescriptorHelper.GetWrapResultAttributeOrNull(request.GetActionDescriptor())
?? _configuration.DefaultWrapResultAttribute;
if (!wrapAttr.WrapOnSuccess)
{
return;
}
if (IsIgnoredUrl(request.RequestUri))
{
return;
}
object resultObject;
if (!response.TryGetContentValue(out resultObject) || resultObject == null)
{
response.StatusCode = HttpStatusCode.OK;
response.Content = new ObjectContent<AjaxResponse>(
new AjaxResponse(),
_configuration.HttpConfiguration.Formatters.JsonFormatter
);
return;
}
if (resultObject is AjaxResponseBase)
{
return;
}
response.Content = new ObjectContent<AjaxResponse>(
new AjaxResponse(resultObject),
_configuration.HttpConfiguration.Formatters.JsonFormatter
);
}
示例3: WithOperationNameBasedOn
private static void WithOperationNameBasedOn(this Telemetry telemetry, HttpRequestMessage request)
{
if (request.HasActionDescriptor())
{
telemetry.OperationName = request.GetActionDescriptor().ActionName;
}
else
{
var leftPart = request.RequestUri.GetLeftPart(UriPartial.Authority);
telemetry.OperationName = new Uri(leftPart).MakeRelativeUri(request.RequestUri).ToString();
}
}
示例4: GetCorsPolicyProvider
public virtual ICorsPolicyProvider GetCorsPolicyProvider(HttpRequestMessage request)
{
if (request == null)
{
throw new ArgumentNullException("request");
}
CorsRequestContext corsRequestContext = request.GetCorsRequestContext();
HttpActionDescriptor actionDescriptor = null;
if (corsRequestContext.IsPreflight)
{
HttpRequestMessage targetRequest = new HttpRequestMessage(new HttpMethod(corsRequestContext.AccessControlRequestMethod), request.RequestUri);
try
{
foreach (var property in request.Properties)
{
// The RouteData and HttpContext from the preflight request properties contain information
// relevant to the preflight request and not the actual request, therefore we need to exclude them.
if (property.Key != HttpPropertyKeys.HttpRouteDataKey &&
property.Key != HttpContextBaseKey)
{
targetRequest.Properties.Add(property.Key, property.Value);
}
}
actionDescriptor = SelectAction(targetRequest);
}
catch
{
if (DefaultPolicyProvider != null)
{
return DefaultPolicyProvider;
}
throw;
}
finally
{
if (targetRequest != null)
{
request.RegisterForDispose(targetRequest);
}
}
}
else
{
actionDescriptor = request.GetActionDescriptor();
}
return GetCorsPolicyProvider(actionDescriptor);
}
示例5: GetPerRequestFormatterInstance
public override MediaTypeFormatter GetPerRequestFormatterInstance(Type type, HttpRequestMessage request, MediaTypeHeaderValue mediaType)
{
HttpActionDescriptor actionDescriptor = request.GetActionDescriptor();
if (actionDescriptor == null)
return base.GetPerRequestFormatterInstance(type, request, mediaType);
var view = actionDescriptor.ControllerDescriptor.ControllerName + "/" +
actionDescriptor.ActionName;
if (actionDescriptor.ControllerDescriptor.Properties.ContainsKey("hb-prefix"))
view = (actionDescriptor.ControllerDescriptor.Properties["hb-prefix"] as string) + "/" + view;
if (request.Properties.ContainsKey("hb-view"))
view = request.Properties["hb-view"] as string;
return new HandlebarsJsonFormatter(_formatter, view, request);
}
示例6: GetCorsPolicyProvider
public virtual ICorsPolicyProvider GetCorsPolicyProvider(HttpRequestMessage request)
{
if (request == null)
{
throw new ArgumentNullException("request");
}
CorsRequestContext corsRequestContext = request.GetCorsRequestContext();
HttpActionDescriptor actionDescriptor = null;
if (corsRequestContext.IsPreflight)
{
HttpRequestMessage targetRequest = new HttpRequestMessage(new HttpMethod(corsRequestContext.AccessControlRequestMethod), request.RequestUri);
try
{
foreach (var property in request.Properties)
{
targetRequest.Properties.Add(property.Key, property.Value);
}
actionDescriptor = SelectAction(targetRequest);
}
catch
{
if (DefaultPolicyProvider != null)
{
return DefaultPolicyProvider;
}
throw;
}
finally
{
if (targetRequest != null)
{
request.RegisterForDispose(targetRequest);
}
}
}
else
{
actionDescriptor = request.GetActionDescriptor();
}
return GetCorsPolicyProvider(actionDescriptor);
}
示例7: WrapResultIfNeeded
protected virtual void WrapResultIfNeeded(HttpRequestMessage request, HttpResponseMessage response)
{
if (!response.IsSuccessStatusCode)
{
return;
}
var wrapAttr = HttpActionDescriptorHelper.GetWrapResultAttributeOrNull(request.GetActionDescriptor())
?? DontWrapResultAttribute.Default;
if (!wrapAttr.WrapOnSuccess)
{
return;
}
object resultObject;
if (!response.TryGetContentValue(out resultObject))
{
return;
}
if (resultObject == null)
{
response.Content = new ObjectContent<AjaxResponse>(
new AjaxResponse(),
_webApiModuleConfiguration.HttpConfiguration.Formatters.JsonFormatter
);
}
if (resultObject is AjaxResponse)
{
return;
}
response.Content = new ObjectContent<AjaxResponse>(
new AjaxResponse(resultObject),
_webApiModuleConfiguration.HttpConfiguration.Formatters.JsonFormatter
);
}
示例8: GetCorsPolicyProvider
public virtual ICorsPolicyProvider GetCorsPolicyProvider(HttpRequestMessage request)
{
if (request == null)
{
throw new ArgumentNullException("request");
}
CorsRequestContext corsRequestContext = request.GetCorsRequestContext();
HttpActionDescriptor actionDescriptor = null;
if (corsRequestContext.IsPreflight)
{
HttpRequestMessage targetRequest = new HttpRequestMessage(new HttpMethod(corsRequestContext.AccessControlRequestMethod), request.RequestUri);
request.RegisterForDispose(targetRequest);
try
{
foreach (var property in request.Properties)
{
// The RouteData and HttpContext from the preflight request properties contain information
// relevant to the preflight request and not the actual request, therefore we need to exclude them.
if (property.Key != HttpPropertyKeys.HttpRouteDataKey &&
property.Key != HttpContextBaseKey)
{
targetRequest.Properties.Add(property.Key, property.Value);
}
}
HttpConfiguration config = request.GetConfiguration();
if (config == null)
{
throw new InvalidOperationException(SRResources.NoConfiguration);
}
IHttpRouteData routeData = config.Routes.GetRouteData(request);
if (routeData == null)
{
// No route data found for selecting action with EnableCorsAttribute, thus no ICorsPolicyProvider is returned
// and let the CorsMessageHandler flow the request to the normal Web API pipeline.
return null;
}
actionDescriptor = SelectAction(targetRequest, routeData, config);
}
catch
{
if (DefaultPolicyProvider != null)
{
return DefaultPolicyProvider;
}
throw;
}
}
else
{
actionDescriptor = request.GetActionDescriptor();
}
return GetCorsPolicyProvider(actionDescriptor);
}
示例9: SetIndentity
protected virtual RequestIdentity SetIndentity(HttpRequestMessage request)
{
var entry = new RequestIdentity();
entry.ClientIp = core.GetClientIp(request).ToString();
entry.Endpoint = request.RequestUri.AbsolutePath.ToLowerInvariant();
entry.ClientKey = request.Headers.Contains("Authorization-Token") ? request.Headers.GetValues("Authorization-Token").First() : "anon";
var actionDescriptor = request.GetActionDescriptor();
if (actionDescriptor == null)
return entry;
entry.ActionName = actionDescriptor.ActionName;
if(actionDescriptor.ControllerDescriptor != null)
entry.ControllerName = actionDescriptor.ControllerDescriptor.ControllerName;
return entry;
}