CSharpTest.Net
AuthenticateAs(NetworkCredential) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.RpcLibrary Assembly > CSharpTest.Net.RpcLibrary Namespace > RpcClientApi Class > AuthenticateAs Method : AuthenticateAs(NetworkCredential) Method

credentials

Glossary Item Box

Adds authentication information to the client, use the static Self to authenticate as the currently logged on Windows user.

Syntax

Visual Basic (Declaration) 
Public Overloads Sub AuthenticateAs( _
   ByVal credentials As NetworkCredential _
) 
C# 
public void AuthenticateAs( 
   NetworkCredential credentials
)

Parameters

credentials

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_WINNT);
    server.StartListening();
    server.OnExecute +=
        delegate(IRpcClientInfo client, byte[] arg)
        {
            Assert.AreEqual(false, client.IsImpersonating);
            using (client.Impersonate())
            {
                Assert.AreEqual(true, client.IsImpersonating);
                using (client.Impersonate())
                    Assert.AreEqual(true, client.IsImpersonating); 
                //does not dispose, we are still impersonating
                Assert.AreEqual(true, client.IsImpersonating);
            }
            Assert.AreEqual(false, client.IsImpersonating);
            return arg;
        };

    using (RpcClientApi client = new RpcClientApi(iid, RpcProtseq.ncacn_np, null, @"\pipe\testpipename"))
    {
        client.AuthenticateAs(RpcClientApi.Self);
        client.Execute(new byte[0]);
    }
}
VB.NETCopy 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_WINNT)
    server.StartListening()
    server.OnExecute += Function(client As IRpcClientInfo, arg As Byte()) Do
        Assert.AreEqual(False, client.IsImpersonating)
        Using client.Impersonate()
            Assert.AreEqual(True, client.IsImpersonating)
            Using client.Impersonate()
                Assert.AreEqual(True, client.IsImpersonating)
            End Using
            'does not dispose, we are still impersonating
            Assert.AreEqual(True, client.IsImpersonating)
        End Using
        Assert.AreEqual(False, client.IsImpersonating)
        Return arg
    End Function

    Using client As New RpcClientApi(iid, RpcProtseq.ncacn_np, Nothing, "\pipe\testpipename")
        client.AuthenticateAs(RpcClientApi.Self)
        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

Generated with Document! X 2011 by Innovasys