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


C# HttpRequest.GetSecureCommunicationPackage方法代码示例

本文整理汇总了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 });
            }
        }
开发者ID:rynnwang,项目名称:CommonSolution,代码行数:64,代码来源:SecuredApiRouter.cs


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