本文整理汇总了C#中System.Web.HttpRequest.GetSecureCommunicationPackage方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequest.GetSecureCommunicationPackage方法的具体用法?C# HttpRequest.GetSecureCommunicationPackage怎么用?C# HttpRequest.GetSecureCommunicationPackage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.GetSecureCommunicationPackage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
/// <summary>
/// Invokes the specified method information.
/// <remarks>
/// Invoke action would regard to method parameter to use difference logic. Following steps show the IF-ELSE case. When it is hit, other would not go through.
/// <list type="number"><item>
/// If input parameter count is 0, invoke without parameter object.
/// </item><item>
/// If input parameter count is 1 and key is not empty or null, invoke using key.
/// </item><item>
/// If input parameter count is 1 and key is empty or null, invoke using key, try to get JSON object from request body and convert to object for invoke.
/// </item><item>
/// If input parameter count more than 1, try read JSON data to match parameters by name (ignore case) in root level, then invoke.
/// </item></list></remarks>
/// </summary>
/// <param name="instance">The instance.</param>
/// <param name="methodInfo">The method information.</param>
/// <param name="httpRequest">The HTTP request.</param>
/// <param name="key">The key.</param>
/// <param name="jsonBody">The json body.</param>
/// <returns>
/// System.Object.
/// </returns>
protected override object Invoke(object instance, MethodInfo methodInfo, HttpRequest httpRequest, string key, out string jsonBody)
{
try
{
var rsaPrivateKey = GravityContext.Current.PrivateKey;
var securePackage = httpRequest.GetSecureCommunicationPackage<JToken>(rsaPrivateKey);
securePackage.CheckNullObject(nameof(securePackage));
var inputParameters = methodInfo.GetParameters();
jsonBody = securePackage.ToString();
if (inputParameters.Length == 0)
{
return methodInfo.Invoke(instance, null);
}
else if (inputParameters.Length == 1)
{
return methodInfo.Invoke(instance, new object[] { securePackage.Data.ToObject(inputParameters[0].ParameterType) });
}
else
{
object[] parameters = new object[inputParameters.Length];
var jsonObject = securePackage.Data as JObject;
if (jsonObject != null)
{
for (int i = 0; i < inputParameters.Length; i++)
{
var jTokenObject = jsonObject.GetProperty(inputParameters[i].Name);
parameters[i] = jTokenObject == null ? null : jTokenObject.ToObject(inputParameters[i].ParameterType);
}
}
return methodInfo.Invoke(instance, parameters);
}
}
catch (Exception ex)
{
throw ex.Handle(new { methodInfo = methodInfo?.GetFullName(), httpRequest = httpRequest?.RawUrl });
}
}