Returns a constant NetworkCredential that represents the Anonymous user
Syntax
Visual Basic (Declaration) | |
---|
Public Shared ReadOnly Property Anonymous As NetworkCredential |
Example
RpcLibrary/RpcLibrary.Test/TestClientInfo.cs
C# | Copy Code |
---|
Guid iid = Guid.NewGuid();
using (RpcServerApi server = new RpcServerApi(iid))
{
server.AddProtocol(RpcProtseq.ncacn_np, @"\pipe\testpipename", 5);
server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_NONE);
server.StartListening();
server.OnExecute +=
delegate(IRpcClientInfo client, byte[] arg)
{
Assert.AreEqual(0, arg.Length);
Assert.AreEqual(RpcAuthentication.RPC_C_AUTHN_NONE, client.AuthenticationLevel);
Assert.AreEqual(RpcProtectionLevel.RPC_C_PROTECT_LEVEL_NONE, client.ProtectionLevel);
Assert.AreEqual(RpcProtoseqType.NMP, client.ProtocolType);
Assert.AreEqual(new byte[0], client.ClientAddress);
Assert.AreEqual(0, client.ClientPid.ToInt32());
Assert.AreEqual(null, client.ClientPrincipalName);
Assert.AreEqual(System.Security.Principal.WindowsIdentity.GetAnonymous().Name, client.ClientUser.Name);
Assert.AreEqual(true, client.IsClientLocal);
Assert.AreEqual(false, client.IsAuthenticated);
Assert.AreEqual(false, client.IsImpersonating);
bool failed = false;
try { client.Impersonate().Dispose(); }
catch (UnauthorizedAccessException) { failed = true; }
Assert.AreEqual(true, failed);
return arg;
};
using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncacn_np, null, @"\pipe\testpipename"))
{
client.AuthenticateAs(RpcClientApi.Anonymous);
client.Execute(new byte[0]);
}
} |
VB.NET | Copy Code |
---|
Dim iid As Guid = Guid.NewGuid()
Using server As New RpcServerApi(iid)
server.AddProtocol(RpcProtseq.ncacn_np, "\pipe\testpipename", 5)
server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_NONE)
server.StartListening()
server.OnExecute += Function(client As IRpcClientInfo, arg As Byte()) Do
Assert.AreEqual(0, arg.Length)
Assert.AreEqual(RpcAuthentication.RPC_C_AUTHN_NONE, client.AuthenticationLevel)
Assert.AreEqual(RpcProtectionLevel.RPC_C_PROTECT_LEVEL_NONE, client.ProtectionLevel)
Assert.AreEqual(RpcProtoseqType.NMP, client.ProtocolType)
Assert.AreEqual(New Byte(0) {}, client.ClientAddress)
Assert.AreEqual(0, client.ClientPid.ToInt32())
Assert.AreEqual(Nothing, client.ClientPrincipalName)
Assert.AreEqual(System.Security.Principal.WindowsIdentity.GetAnonymous().Name, client.ClientUser.Name)
Assert.AreEqual(True, client.IsClientLocal)
Assert.AreEqual(False, client.IsAuthenticated)
Assert.AreEqual(False, client.IsImpersonating)
Dim failed As Boolean = False
Try
client.Impersonate().Dispose()
Catch generatedExceptionName As UnauthorizedAccessException
failed = True
End Try
Assert.AreEqual(True, failed)
Return arg
End Function
Using client As New RpcClientApi(iid, RpcProtseq.ncacn_np, Nothing, "\pipe\testpipename")
client.AuthenticateAs(RpcClientApi.Anonymous)
client.Execute(New Byte(0) {})
End Using
End Using |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also