LogonAs Method (String, String, NetworkCredential, String, String, String, String)
The LogonAs method connects to Microsoft Dynamics AX on behalf of a specific Microsoft Dynamics AX user.
Assembly: Microsoft.Dynamics.BusinessConnectorNet (in Microsoft.Dynamics.BusinessConnectorNet.dll)
public: void LogonAs( String^ user, String^ domain, NetworkCredential^ bcProxyCredentials, String^ company, String^ language, String^ objectServer, String^ configuration )
Parameters
- user
- Type: System.String
- domain
- Type: System.String
- bcProxyCredentials
- Type: System.Net.NetworkCredential
- company
- Type: System.String
- language
- Type: System.String
- objectServer
- Type: System.String
- configuration
- Type: System.String
| Exception | Condition |
|---|---|
| AlreadyLoggedOnException |
The requested operation cannot be performed because the user is already logged on to Microsoft Dynamics AX. |
| BusinessConnectorException |
An unexpected error has occurred with Business Connector. |
| LogonSystemChangedException |
The logon failed because the logon parameters do not match those currently being used in Business Connector because of a previous logon is using that instance of the Business Connector. |
| NoSecurityKeyException |
The requested operation cannot be performed because the required security key does not exist. |
| ArgumentException |
An argument passed to the method is invalid. |
| ArgumentNullException |
A null reference was passed to a method that does not accept it as a valid argument. |
| OutOfMemoryException |
There is insufficient memory to complete the requested operation. |
The LogonAs method connects to Microsoft Dynamics AX on behalf of a specific Microsoft Dynamics AX user. The namespace is the Microsoft.Dynamics.BusinessConnectorNet in the Microsoft.Dynamics.BusinessconnectorNet.dll.
You can create a NetworkCredential object with the following code:
System.Net.NetworkCredential creds = new System.Net.NetworkCredential(
ADUserName, ADUserPassword, ADDomain)
The following code example uses the local configuration for the required parameters.
Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx; DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta(); DynAx.LogonAs("","",null,"","","","");
The following code example uses the local configuration for the required parameters. It also specifies the Microsoft Dynamics AX user ID value.
Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx; DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta(); DynAx.LogonAs(Environment.UserName,"",null,"","","","");
The following code example uses the local configuration for the required parameters. It also specifies the user ID value and the fully qualified domain name that the user ID is a part of.
Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx; DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta(); DynAx.LogonAs(Environment.UserName,"FullyQualifiedDomainName",null,"", "","","");
The following code example uses the local configuration for the required parameters. It also specifies the user ID value, the fully qualified domain name that the user ID is a part of, and the bcProxyCredentials parameter to match the proxy settings in Microsoft Dynamics AX. You can access the proxy user settings in the Administration menu. From the navigation pane, select Administration, expand the Security node, and then select BusinessConnectorProxy.
Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx; DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta(); System.Net.NetworkCredential nc = new System.Net.NetworkCredential("ProxyUserId", "password"); DynAx.LogonAs(Environment.UserName,"FullyQualifiedDomainName",nc,"","","","");
The following code example uses the local configuration for the required parameters. It also specifies the user ID value, the fully qualified domain name that the user ID is a part of, the bcProxyCredentials parameter to match the proxy settings in Microsoft Dynamics AX, and the company value.
Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx; DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta(); System.Net.NetworkCredential nc = new System.Net.NetworkCredential("ProxyUserId", "password"); DynAx.LogonAs(Environment.UserName,"FullyQualifiedDomainName",nc,"dat", "","","");
The following code example uses the local configuration for the required parameters. It also specifies the user ID value, the fully qualified domain name that the user ID is a part of, the bcProxyCredentials parameter to match the proxy settings in Microsoft Dynamics AX, the company value, and the language value.
Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx; DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta(); System.Net.NetworkCredential nc = new System.Net.NetworkCredential("ProxyUserId", "password"); DynAx.LogonAs(Environment.UserName,"FullyQualifiedDomainName",nc,"dat", "en-us","","");
This example uses the local configuration for the required parameters. It also specifies the user ID value, the fully qualified domain name that the user ID is a part of, the bcProxyCredentials parameter to match the proxy settings in Microsoft Dynamics AX, the company value, the language value, and the object server value is set for the AOS server parameter. The following table provides the AOS server details.
|
AOS server property |
Value |
|---|---|
|
AOSServerInstance |
Company1 |
|
Server name |
AOS |
|
TCP/IP port number |
2713 |
The following code illustrates this example.
Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx; DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta(); System.Net.NetworkCredential nc = new System.Net.NetworkCredential("ProxyUserId", "password"); DynAx.LogonAs(Environment.UserName,"FullyQualifiedDomainName",nc,"dat", "en-us","company1@AOS:2713","");
This example uses the local configuration for the required parameters. It also specifies the user ID value, the fully qualified domain name that the user ID is a part of, the bcProxyCredentials parameter to match the proxy settings in Microsoft Dynamics AX, the company value, the language value, the object server value is set for the AOS parameter, and the configuration value is the client configuration name or specified to a client configuration file. The following table provides the AOS details.
|
AOS property |
Value |
|---|---|
|
AOSServerInstance |
Company1 |
|
Server name |
AOS |
|
TCP/IP port number |
2713 |
With a client configuration file, notice the use of two backslashes (\\) for the path specification. A port must be specified within the client configuration.
The following code illustrates this example.
Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx; DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta(); System.Net.NetworkCredential nc = new System.Net.NetworkCredential("ProxyUserId", "password"); DynAx.LogonAs(Environment.UserName,"FullyQualifiedDomainName",nc,"dat", "en-us"," company1@AOS:2713","AXClient"); DynAx.LogonAs(Environment.UserName,"FullyQualifiedDomainName",nc,"dat", "en-us","company1@AOS:2713","c:\\Client.axc");
This example does not specify the proxy user. The user that is logged in is used. This scenario is only appropriate when testing the connection to the .NET Business Connector. When you move to a production environment, you must pass the appropriate parameters in the method call.
To implement this example, you must do the following:
-
Start AOS.
-
In Microsoft Visual Studio, create a new C# project called LogonAs_Example.
-
Add a Button and a RichTextBox control to the form.
-
Add a reference to the Microsoft.Dynamics.BusinessConnectorNet.dll assembly in the C:\Program Files\Microsoft Dynamics AX\40\Client\Bin folder.
Add the following code on the click event of the button control.
private void button1_Click(object sender, EventArgs e) { Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx; // Create a user, and then associate it with the user // that is currently logged in. DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta(); try { // Test the connection to the .NET Business Connector. DynAx.LogonAs(Environment.UserName, "", null, "", "", "", ""); richTextBox1.Text = "Success"; } catch (Exception ex) { MessageBox.Show(ex.ToString()); MessageBox.Show(ex.Message); } }
This example uses C# code where the proxy user is specified. This example uses a different user ID than the user ID that is currently logged in.
To implement this example, you must do the following:
-
Start AOS.
-
In Visual Studio, create a new C# project called LogonAs_ExamplewithProxy.
-
Add a Button and a RichTextBox control to the form.
-
Add a reference to the Microsoft.Dynamics.BusinessConnectorNet.dll assembly in the C:\Program Files\Microsoft Dynamics AX\40\Client\Bin folder.
-
Within Microsoft Dynamics AX, set up your proxy user. From the navigation pane, select Administration, expand the Security node, and then select BusinessConnectorProxy. Enter the same user ID credentials that you specify in the code. Fill in the alias with your user ID and the network domain with a fully qualified domain name that the user ID is a part of.
The code is placed on the click event of the button control.
private void button1_Click(object sender, EventArgs e) { Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx; // Add the proxy user. // Use a hard-coded string for the "ProxyUserID" and "password" that // matches the proxy that you specified in the Business Connector Proxy. // Replace the ProxyUserID and password with the // proxy user name and password. System.Net.NetworkCredential nc = new System.Net.NetworkCredential("ProxyUserID", "password"); string strUserName; // Set the user to the proxy user specified in the Business Connector Proxy. // Replace the ProxyUserID with the proxy user name. DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta(); strUserName = "ProxyUserID"; // Test the connection to the .NET Business Connector // by using the proxy user. try { DynAx.LogonAs(strUserName.Trim(), "", nc, "", "", "", ""); richTextBox1.Text = "Success"; } catch (Exception ex) { MessageBox.Show(ex.ToString()); MessageBox.Show(ex.Message); } }