本文整理汇总了C#中System.Web.HttpContext.TryGetRequest方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContext.TryGetRequest方法的具体用法?C# HttpContext.TryGetRequest怎么用?C# HttpContext.TryGetRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpContext
的用法示例。
在下文中一共展示了HttpContext.TryGetRequest方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUserIPFromRequest
private static string GetUserIPFromRequest(HttpContext httpContext, OperationContext operationContext)
{
if (operationContext != null)
{
// UserIPHeader
int headerIndex = operationContext.IncomingMessageHeaders.FindHeader(XMS.Core.WCF.UserIPHeader.Name, XMS.Core.WCF.UserIPHeader.NameSpace);
if (headerIndex >= 0)
{
// 传入请求中存在验证票据时,当前会员身份为验证票据指示的身份
return operationContext.IncomingMessageHeaders.GetHeader<string>(headerIndex);
}
return operationContext.IncomingMessageProperties.GetIP();
}
if (httpContext != null)
{
System.Web.HttpRequest httpRequest = httpContext.TryGetRequest();
if (httpRequest != null)
{
return httpRequest.GetIP();
}
}
return "127.0.0.1";
}
示例2: GetFromRequest
/// <summary>
/// 从请求中获取应用代理对象。
/// </summary>
/// <returns></returns>
internal static AppAgent GetFromRequest(HttpContext httpContext, OperationContext operationContext)
{
AppAgent agent = null;
if (operationContext != null)
{
int headerIndex = operationContext.IncomingMessageHeaders.FindHeader(XMS.Core.WCF.AppAgentHeader.Name, XMS.Core.WCF.AppAgentHeader.NameSpace);
if (headerIndex >= 0)
{
agent = Parse(operationContext.IncomingMessageHeaders.GetHeader<string>(headerIndex));
if (agent != null)
{
return agent;
}
}
if (operationContext.IncomingMessageProperties.ContainsKey(HttpRequestMessageProperty.Name))
{
HttpRequestMessageProperty requestMessageProperty = operationContext.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
if (requestMessageProperty != null)
{
agent = Parse(requestMessageProperty.Headers.Get(XMS.Core.WCF.AppAgentHeader.Name));
if (agent != null)
{
return agent;
}
}
}
}
if (httpContext != null)
{
System.Web.HttpRequest httpRequest = httpContext.TryGetRequest();
if (httpRequest != null)
{
// 从查询参数中获取代理并用完整模式解析
agent = Parse(httpRequest[XMS.Core.WCF.AppAgentHeader.Name]);
if (agent == null)
{
// 从Asp.Net底层生成代理
agent = new AppAgent(false, null);
agent.name = httpRequest.Browser.Browser;
agent.version = httpRequest.Browser.Version;
agent.platform = httpRequest.Browser.Platform;
agent.isMobileDevice = httpRequest.Browser.IsMobileDevice;
agent.mobileDeviceModel = httpRequest.Browser.MobileDeviceModel;
agent.mobileDeviceManufacturer = httpRequest.Browser.MobileDeviceManufacturer;
agent.mobileDeviceId = httpRequest["DeviceID"];
}
return agent;
}
}
if (agent == null)
{
return AppAgent.Empty;
}
return agent;
}
示例3: GetFromRequest
/// <summary>
/// 从请求中获取并生成ServiceInvokeChain调用链对象。
/// </summary>
/// <returns></returns>
internal static ServiceInvokeChain GetFromRequest(HttpContext httpContext, OperationContext operationContext)
{
List<ServiceInvokeChainNode> list = null;
if (operationContext != null)
{
int headerIndex = operationContext.IncomingMessageHeaders.FindHeader(XMS.Core.WCF.InvokeChainHeader.name, XMS.Core.WCF.InvokeChainHeader.nameSpace);
if (headerIndex >= 0)
{
list = Parse(operationContext.IncomingMessageHeaders.GetHeader<string>(headerIndex));
}
if(list == null)
{
if (operationContext.IncomingMessageProperties.ContainsKey(HttpRequestMessageProperty.Name))
{
HttpRequestMessageProperty requestMessageProperty = operationContext.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
if (requestMessageProperty != null)
{
list = Parse(requestMessageProperty.Headers.Get(XMS.Core.WCF.InvokeChainHeader.name));
}
}
}
if(list == null)
{
list = new List<ServiceInvokeChainNode>();
}
if (operationContext.IncomingMessageHeaders != null)
{
if (list.Count == 0)
{
list.Add(ServiceInvokeChainNode.CreateHeader(operationContext.IncomingMessageProperties.GetIP()));
}
else
{
list[list.Count - 1].SetIP(operationContext.IncomingMessageProperties.GetIP());
}
}
// 将当前应用程序加入到调用链的尾部(如果调用链从当前应用开始,那么当前应用程序同时位于调用链的头部)
list.Add(ServiceInvokeChainNode.CreateTail(RunContext.AppName, RunContext.AppVersion));
return new ServiceInvokeChain(list.ToArray());
}
if (httpContext != null)
{
System.Web.HttpRequest httpRequest = httpContext.TryGetRequest();
if (httpRequest != null)
{
list = Parse(httpRequest[XMS.Core.WCF.InvokeChainHeader.name]);
}
if (list == null)
{
list = new List<ServiceInvokeChainNode>();
}
if (httpRequest != null)
{
if (list.Count == 0)
{
list.Add(ServiceInvokeChainNode.CreateHeader(httpRequest.GetIP()));
}
else
{
list[list.Count - 1].SetIP(httpRequest.GetIP());
}
}
// 将当前应用程序加入到调用链的尾部(如果调用链从当前应用开始,那么当前应用程序同时位于调用链的头部)
list.Add(ServiceInvokeChainNode.CreateTail(RunContext.AppName, RunContext.AppVersion));
return new ServiceInvokeChain(list.ToArray());
}
return null;
}