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


C# HttpListenerContext.Disconnect方法代码示例

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


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

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