C# 域不可用时使用NegotiateStream

C# 域不可用时使用NegotiateStream,c#,dns,windows-authentication,offline,C#,Dns,Windows Authentication,Offline,我正在使用NegotiateStream对客户机/服务器应用程序进行身份验证。服务器端代码如下所示: SecureStream = new NegotiateStream(Stream, true); SecureStream.AuthenticateAsServer( CredentialCache.DefaultNetworkCredentials, ProtectionLevel.EncryptAndSign, TokenImpersonationLevel.Id

我正在使用NegotiateStream对客户机/服务器应用程序进行身份验证。服务器端代码如下所示:

SecureStream = new NegotiateStream(Stream, true);

SecureStream.AuthenticateAsServer(
    CredentialCache.DefaultNetworkCredentials,
    ProtectionLevel.EncryptAndSign,
    TokenImpersonationLevel.Identification);

if (!SecureStream.IsAuthenticated)
{
    return false;
}
WindowsPrincipal principal = new WindowsPrincipal(
    (WindowsIdentity)SecureStream.RemoteIdentity);

// ExpectedRoles is a string[] of possible roles
foreach (string role in ExpectedRoles)
{
    if (principal.IsInRole(role))
        return true;
}
SecureStream = new NegotiateStream(Stream, true);
SecureStream.AuthenticateAsClient();
if (!SecureStream.IsAuthenticated)
{
    return false;
}
客户端代码如下所示:

SecureStream = new NegotiateStream(Stream, true);

SecureStream.AuthenticateAsServer(
    CredentialCache.DefaultNetworkCredentials,
    ProtectionLevel.EncryptAndSign,
    TokenImpersonationLevel.Identification);

if (!SecureStream.IsAuthenticated)
{
    return false;
}
WindowsPrincipal principal = new WindowsPrincipal(
    (WindowsIdentity)SecureStream.RemoteIdentity);

// ExpectedRoles is a string[] of possible roles
foreach (string role in ExpectedRoles)
{
    if (principal.IsInRole(role))
        return true;
}
SecureStream = new NegotiateStream(Stream, true);
SecureStream.AuthenticateAsClient();
if (!SecureStream.IsAuthenticated)
{
    return false;
}
客户机和服务器可以在同一域的不同网段上运行。因此,如果它们位于与域控制器不同的网段上,并且internet连接中断,它们应该能够以脱机方式运行。问题是,某些域被配置为用户无法在域断开连接模式下进行身份验证(显然,关闭该功能是一种安全措施)

因此,我正在尝试找出一种身份验证模型,该模型允许我在域不可用时将非域用户作为备用位置进行身份验证。

Kerberos(以及在较小程度上的NTLM)非常容忍服务器和DC之间的瞬时网络中断。一旦用户为服务器获得了有效的路边罚单,即使服务器(或客户机)无法联系DC,服务器也将继续对用户进行身份验证。这类票据的默认生存期为10小时,通常涵盖日常工作日内短暂停机的人员

NTLM会话的缓存时间大约为15分钟(我上一次对此进行检查是在4-5年前),因此暂时性中断必须比“一个小时或三个小时”更短暂


客户机(或服务器)和DCs之间的预期停机时间范围是多少?[旁白:如果真的很糟糕,为什么不调查一下在有损网段的近端放置一个低功耗DC(如果你运行的是2008年的广告,甚至是只读副本)?

不幸的是,我是一个程序员,不是一个网络专家,所以我不知道如何描述这个问题。但我的理解是,有一些设置会禁用您在此处描述的默认行为(出于安全原因),某些网络管理员会将其禁用(出于安全原因),但仍希望软件正常工作。我会提出设立二级DC的建议,看看他们对此有何看法。但除了提供建议,我在网络配置方面没有太多发言权。我认为更糟糕的情况可能是在几天的时间内出现停机,但我不知道这种情况有多普遍。一整天可能并非闻所未闻,这将涉及使用物理媒体复制数据。