本文整理汇总了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;
}
}