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


C# IHttpRequest.GetParam方法代码示例

本文整理汇总了C#中IHttpRequest.GetParam方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpRequest.GetParam方法的具体用法?C# IHttpRequest.GetParam怎么用?C# IHttpRequest.GetParam使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IHttpRequest的用法示例。


在下文中一共展示了IHttpRequest.GetParam方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeserializeJsonFromGet

        public static void DeserializeJsonFromGet(IHttpRequest req, IHttpResponse res, object dto)
        {
            if (dto == null)
            {
                return;
            }

            var requestDto = dto as IRequest;
            if (requestDto != null && req.GetHttpMethodOverride() == "GET" &&  IsJson(req))
            {
                var data = req.GetParam("data");
                if (data != null)
                {
                    var requestModelType = dto.GetType().BaseType.GetGenericArguments()[0];
                    requestDto.Data = ServiceStack.Text.JsonSerializer.DeserializeFromString(data, requestModelType);
                }

                var user = req.GetParam("user");
                if (user != null)
                {
                    requestDto.User = ServiceStack.Text.JsonSerializer.DeserializeFromString(user, typeof(ApiIdentity)) as ApiIdentity;
                }
            }
        }
开发者ID:vivekmalikymca,项目名称:BetterCMS,代码行数:24,代码来源:GetRequestProcessor.cs

示例2: ResolveAndExecuteRazorPage

        public IRazorView ResolveAndExecuteRazorPage(IHttpRequest httpReq, IHttpResponse httpRes, object model, RazorPage razorPage=null)
        {
            razorPage = razorPage ?? FindRazorPage(httpReq, model);

            if (razorPage == null)
            {
                httpRes.StatusCode = (int)HttpStatusCode.NotFound;
                return null;
            }

            using (var writer = new StreamWriter(httpRes.OutputStream, UTF8EncodingWithoutBom))
            {
                var page = CreateRazorPageInstance(httpReq, httpRes, model, razorPage);

                var includeLayout = !(httpReq.GetParam(QueryStringFormatKey) ?? "").Contains(NoTemplateFormatValue);
                if (includeLayout)
                {
                    var result = ExecuteRazorPageWithLayout(httpReq, httpRes, model, page, () =>
                    {
                        return httpReq.GetItem(LayoutKey) as string
                                       ?? page.Layout
                                       ?? DefaultLayoutName;
                    });

                    writer.Write(result.Item2);
                    return result.Item1;
                }

                page.WriteTo(writer);
                return page;
            }
        }
开发者ID:yeurch,项目名称:ServiceStack,代码行数:32,代码来源:RazorPageResolver.cs

示例3: HasValidAuthSecret

        /// <summary>Query if 'req' has valid authentication secret.</summary>
        ///
        /// <param name="req">The request.</param>
        ///
        /// <returns>true if valid authentication secret, false if not.</returns>
        public bool HasValidAuthSecret(IHttpRequest req)
        {
            if (AdminAuthSecret != null)
            {
                var authSecret = req.GetParam("authsecret");
                return authSecret == EndpointHost.Config.AdminAuthSecret;
            }

            return false;
        }
开发者ID:Qasemt,项目名称:NServiceKit,代码行数:15,代码来源:EndpointHostConfig.cs

示例4: HasValidAuthSecret

        public bool HasValidAuthSecret(IHttpRequest httpReq)
        {
            if (Config.AdminAuthSecret != null)
            {
                var authSecret = httpReq.GetParam("authsecret");
                return authSecret == Config.AdminAuthSecret;
            }

            return false;
        }
开发者ID:rjdudley,项目名称:ServiceStack,代码行数:10,代码来源:ServiceStackHost.Runtime.cs

示例5: ResolveAndExecuteRazorPage

        public IRazorView ResolveAndExecuteRazorPage(IHttpRequest httpReq, IHttpResponse httpRes, object model, RazorPage razorPage=null)
        {
            var viewName = httpReq.GetItem(ViewKey) as string;
            if (razorPage == null && viewName != null)
            {
                razorPage = this.viewManager.GetPageByName(viewName);
            }
            else
            {
                razorPage = razorPage
                    ?? this.viewManager.GetPageByName(httpReq.OperationName) //Request DTO
                    ?? this.viewManager.GetPage(httpReq, model);  // Response DTO
            }

            if (razorPage == null)
            {
                httpRes.StatusCode = (int)HttpStatusCode.NotFound;
                return null;
            }
            
            using (var writer = new StreamWriter(httpRes.OutputStream, UTF8EncodingWithoutBom))
            {
                var page = CreateRazorPageInstance(httpReq, httpRes, model, razorPage);

                var includeLayout = !(httpReq.GetParam(QueryStringFormatKey) ?? "").Contains(NoTemplateFormatValue);
                if (includeLayout)
                {
                    using (var ms = new MemoryStream())
                    using (var childWriter = new StreamWriter(ms, UTF8EncodingWithoutBom))
                    {
                        //child page needs to execute before master template to populate ViewBags, sections, etc
                        page.WriteTo(childWriter);

                        var layout = httpReq.GetItem(LayoutKey) as string
                            ?? page.Layout
                            ?? DefaultLayoutName;

                        var childBody = ms.ToArray().FromUtf8Bytes();
                        var layoutPage = this.viewManager.GetPageByName(layout, httpReq, model);
                        if (layoutPage != null)
                        {
                            var layoutView = CreateRazorPageInstance(httpReq, httpRes, model, layoutPage);

                            layoutView.SetChildPage(page, childBody);
                            layoutView.WriteTo(writer);
                            return layoutView;
                        }

                        writer.Write(childBody);
                        return page;
                    }
                }

                page.WriteTo(writer);
                return page;
            }
        }
开发者ID:manuelnelson,项目名称:ServiceStack,代码行数:57,代码来源:RazorPageResolver.cs

示例6: Execute

 /// <summary>This method is only executed if the HTTP method matches the <see cref="ApplyTo"/> property.</summary>
 ///
 /// <param name="req">       The http request wrapper.</param>
 /// <param name="res">       The http response wrapper.</param>
 /// <param name="requestDto">The request DTO.</param>
 public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
 {
     req.Items["View"] = req.GetParam("View");
     req.Items["Template"] = req.GetParam("Template");
 }
开发者ID:Qasemt,项目名称:NServiceKit,代码行数:10,代码来源:ClientCanSwapTemplatesAttribute.cs

示例7: GetRequests

        private IEnumerable<PostmanRequest> GetRequests(IHttpRequest request, ServiceMetadata metadata, string parentId, IEnumerable<Operation> operations)
        {
            var feature = EndpointHost.GetPlugin<PostmanFeature>();
            var label = request.GetParam("label") ?? feature.DefaultLabel;

            var customHeaders = request.GetParam("headers");
            var headers = customHeaders == null ? feature.DefaultHeaders : customHeaders.Split(',');

            foreach (var op in metadata.OperationsMap.Values.Where(o => metadata.IsVisible(request, o)))
            {
                var exampleObject = ReflectionUtils.PopulateObject(op.RequestType.CreateInstance()).ToStringDictionary();
                
                var data = op.RequestType.GetSerializableFields().Select(f => f.Name)
                    .Concat(op.RequestType.GetSerializableProperties().Select(p => p.Name))
                    .ToDictionary(f => f, f => exampleObject.GetValueOrDefault(f));

                foreach (var route in op.Routes)
                {
                    var routeVerbs = route.AllowsAllVerbs ? new[] { "POST" } : route.AllowedVerbs.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                    var restRoute = new RestRoute(route.RequestType, route.Path, route.AllowedVerbs);

                    foreach (var verb in routeVerbs)
                    {
                        yield return new PostmanRequest
                        {                            
                            Id = Guid.NewGuid().ToString(),
                            Headers = string.Join("\n", headers),
                            Method = verb,
                            Url = CalculateAppUrl(request, _aspnetSubPath) + restRoute.Path.ReplaceVariables(),
                            Name = label.FormatLabel(op.RequestType, restRoute.Path),
                            Description = op.RequestType.GetDescription(),
                            PathVariables = restRoute.Variables.ToDictionary(v => v, v => data.GetValueOrDefault(v)),
                            Data = data.Keys.Except(restRoute.Variables).Select(v => new PostmanData
                            {
                                Key = v,
                                Value = data[v],
                                Type = "text",
                            }).ToArray(),
                            DataMode = "params",                            
                            Version = 2,
                            Time = DateTime.UtcNow.ToUnixTimeMs(),
                            CollectionId = parentId,
                            Folder = restRoute.Path.GetFolderName()
                        };
                    }
                }
            }
        }
开发者ID:wwwlicious,项目名称:ServiceStack.Api.Postman,代码行数:49,代码来源:PostmanMetadataHandler.cs


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