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


C# IHttpRequest.TryGetItemId方法代码示例

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


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

示例1: ProcessSection

        protected override bool ProcessSection(IHttpRequest request, IHttpResponse response, IHttpSession session)
        {
            if (request.UriParts.Length == 1)
            {
                PermissionDeniedMessage pmsg;
                var listmsg = Connections.SendAndReceive<UserListMessage> (new RequestUserListMessage(UserListMode.All), session, out pmsg);

                if (pmsg != null)
                {
                    WriteAndFlush (response, "{ \"error\": \"Permission denied\" }");
                    return true;
                }

                WriteAndFlush (response, JsonConvert.SerializeObject (listmsg.Users.RunQuery (request.QueryString)));
                return true;
            }
            else if (request.UriParts.Length == 2)
            {
                int userId;
                if (!request.TryGetItemId (out userId))
                {
                    WriteAndFlush (response, "{ \"error\": \"Invalid request\" }");
                    return true;
                }

                switch (request.UriParts[1].Trim().ToLower())
                {
                    //case "delete":
                    case "edit":
                    {
                        IHttpInput input = (request.Method.ToLower() == "post") ? request.Form : request.QueryString;

                        if (!input.ContainsAndNotNull ("SessionId", "Permissions") || session.Id != input["SessionId"].Value)
                        {
                            WriteAndFlush (response, "{ \"error\": \"Invalid request\" }");
                            return true;
                        }

                        var permissions = JsonConvert.DeserializeObject<IEnumerable<Permission>> (input["Permissions"].Value).ToList();
                        if (permissions.Count == 0)
                            return true;

                        Connections.Send (new SetPermissionsMessage (userId, permissions), session);
                        return true;
                    }
                }
            }

            WriteAndFlush (response, "{ \"error\": \"Invalid request\" }");
            return true;
        }
开发者ID:ermau,项目名称:Gablarski,代码行数:51,代码来源:UserModule.cs

示例2: ProcessSection

        protected override bool ProcessSection(IHttpRequest request, IHttpResponse response, IHttpSession session)
        {
            if (request.UriParts.Length == 1)
            {
                PermissionDeniedMessage denied;
                var msg = Connections.SendAndReceive<ChannelListMessage> (
                    new RequestChannelListMessage(), session, out denied);

                if (denied != null)
                {
                    WriteAndFlush (response, "{ \"error\": \"Permission denied\" }");
                    return true;
                }

                WriteAndFlush (response, JsonConvert.SerializeObject (new { DefaultChannel = msg.DefaultChannelId, Channels = msg.Channels.RunQuery (request.QueryString) }));
            }
            else if (request.UriParts.Length == 2)
            {
                /*if (request.Method.ToLower() != "post")
                    return false;*/

                IHttpInput input = (request.Method.ToLower() == "post") ? request.Form : request.QueryString;

                int channelId;
                switch (request.UriParts[1])
                {
                    case "delete":
                    case "edit":
                    {
                        if (!request.TryGetItemId (out channelId))
                        {
                            WriteAndFlush (response, "{ \"error\": \"Invalid channel ID\" }");
                            return true;
                        }

                        return SaveOrUpdateChannel (session, response, input, channelId, (request.UriParts[1] == "delete"));
                    }

                    case "new":
                        return SaveOrUpdateChannel (session, response, input, 0, false);
                }
            }
            else
            {
                return false;
            }

            return true;
        }
开发者ID:ermau,项目名称:Gablarski,代码行数:49,代码来源:ChannelModule.cs


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