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


C# HttpListenerContext.WriteString方法代码示例

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


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

示例1: ParseAndProcess

        public static void ParseAndProcess(WebKit webKit, HttpListenerContext context, string[] args, string user, string ipAddress)
        {
            try
            {
                if (args != null && args.Length > 0)
                {
                    //paremeters.Clear();

                    string id = args.ElementAt(0).Trim();

                    if (id != null && id.Length > 0)
                    {
                        RemoveFirst(ref args);

                        for (var i = 0; i < args.Length; i++)
                        {
                            var arg = args[i].ToString();
                            if (arg.Length > 0)
                            {
                                if (arg.Contains('='))
                                    arg = arg.Remove(0, arg.IndexOf('=') + 1).Trim();

                                if (arg.Length > 0)
                                    args[i] = arg;
                            }
                        }

                        var arguments = new Args()
                        {
                            Arguments = args,
                            AuthName = user,
                            IpAddress = ipAddress,
                            WebKit = webKit
                        };

                        //InsertAtFirst(
                        //Data.Insert(0, IPAddress);

                        //foreach (string param in Data)
                        //{
                        //    string parameter = param.Trim();
                        //    if (parameter.Length > 0)
                        //    {
                        //        if (parameter.Contains('='))
                        //        {
                        //            parameter = parameter.Remove(0, parameter.IndexOf('=') + 1);
                        //        }
                        //        paremeters.Add(parameter);
                        //    }
                        //}

                        //paremeters.Insert(0, WebKit);

                        //var args = new Args()
                        //{
                        //    WebKit = WebKit,
                        //    Sender = new Utility.WebSender(
                        //};

                        var serialized = ProcessPacket(id, arguments);
                        context.WriteString(String.Empty, serialized);
                    }
                }
            }
            catch (ExitException) { throw; }
            catch (HttpListenerException) { }
            catch (ArgumentException) { }
            catch (Exception e)
            {
                ProgramLog.Log(e);
            }
        }
开发者ID:DeathCradle,项目名称:TDSM-Web-Kit,代码行数:72,代码来源:Parser.cs

示例2: CheckAuthenticity

        public static bool CheckAuthenticity(HttpListenerContext context, WebKit webkit, string httpData, string ipAddress)
        {
            var identity = context.User.Identity;

            int slot;
            if (NeedsKick(ipAddress, identity.Name, webkit, out slot))
            {
                RemoveKickedUser(ipAddress, identity.Name, webkit, slot);

                var res = new Dictionary<String, Object>();
                res["main-interval-rm"] = "http://tdsm.org";
                var serialized = Json.Serialize(webkit.WebServer, res);
                context.WriteString(serialized);

                WebKit.Log("{0} disconnected from {1}", identity.Name, ipAddress ?? "HTTP");
                return false;
            }

            switch (identity.AuthenticationType)
            {
                case "Basic":
                    var basicIdentity = (identity as HttpListenerBasicIdentity).ToTDSMIdentity(webkit);

                    lock (webkit.WebSessions)
                    {
                        if (basicIdentity.AuthStatus != AuthStatus.MATCH)
                        {
                            context.Disconnect("Credentials incorrect.");
                            WebKit.Log("{0} disconnected from {1}", basicIdentity.Name, ipAddress ?? "HTTP");
                            return false;
                        }
                        else
                        {
                            Identity ident;
                            if (!webkit.WebSessions.ContainsKey(basicIdentity.Name))
                                WebKit.Log("{0} logged in from {1}", basicIdentity.Name, ipAddress ?? "HTTP");
                            else if (webkit.WebSessions.TryGetValue(basicIdentity.Name, out ident))
                            {
                                if ((DateTime.Now - ident.LastUpdate).TotalMilliseconds > (webkit.MainUpdateInterval * 2))
                                    WebKit.Log("{0} logged in from {1}", basicIdentity.Name, ipAddress ?? "HTTP");
                            }
                        }

                        if (webkit.WebSessions.ContainsKey(basicIdentity.Name))
                        {
                            var newIdent = webkit.WebSessions[basicIdentity.Name];
                            newIdent.IpAddress = ipAddress;
                            newIdent.LastUpdate = DateTime.Now;
                            webkit.WebSessions[basicIdentity.Name] = newIdent;
                        }
                        else
                            webkit.WebSessions[basicIdentity.Name] = new Identity()
                            {
                                IpAddress = ipAddress,
                                LastUpdate = DateTime.Now
                            };
                    }
                    return true;
                //case "NTLM":
                //    var identity = iIdentity as WindowsIdentity;
                //    var ident1 = iIdentity as System.Security.Principal.WindowsPrincipal;
                //    var ident2 = iIdentity as System.Security.Principal.GenericPrincipal;
                //    var ident3 = iIdentity as System.Security.Principal.GenericIdentity;
                //    break;
                default:
                    context.Disconnect("Unauthorised access.");
                    WebKit.Log("Connection is unsupported from {0}@{1}", identity.Name, ipAddress ?? "HTTP");
                    return false;
            }
        }
开发者ID:DeathCradle,项目名称:TDSM-Web-Kit,代码行数:70,代码来源:Html.cs


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