web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Business Central API call with HttpClient.UseWindowsAuthentication and Error 401

Andrey Baludin Profile Picture Andrey Baludin 3,941

Hello Team!

Today we will work with next scenario:

1. Work with AL language

2. We have on-premise Business Central Spring'19 release (any localization) installed on Azure VM with DNS (like myvm.westeurope.cloudapp.azure.com).

UseWindowsAuthentication feature were introduced at December'18 and works only for on-premise BC

3. We have Windows credentials on Business Central instance.

4. We are planning to send data (call an BC API) from same tenant to same tenant. So I just want to replicate data between 2 companies on the same database using API.

5. When i'm calling BC API with Postman - everything works smoothly, but when i'm using

Client.UseWindowsAuthentication(Username, Password);

Client.Get(URL, ResponseMessage);

nothing works. And this construction also not working:

Client.UseWindowsAuthentication(Username, Password, Domain);

Client.Get(URL, ResponseMessage);

"Not working" - means I'm getting Error 401 Unauthorized each call instead of getting 200 Ok

So after googling and asking in Yammer I found next solution:

https://victormaceda.wordpress.com/2010/04/20/you-receive-error-401-1-when-you-browse-a-web-site-that-uses-integrated-authentication-and-is-hosted-on-iis-5-1-or-a-later-version/

I used 2nd method:

Specify host names

To specify the host names that are mapped to the loopback address and can connect to Web sites on your computer, follow these steps:

  1. Set the DisableStrictNameChecking registry entry to 1. (http://www.happysysadm.com/2011/11/setting-disablestrictnamechecking-in.html)
  2. Click Start, click Run, type regedit, and then click OK.
  3. Locate and then click the following registry subkey:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
  4. Right-click MSV1_0, point to
    New, and then click Multi-String Value.
  5. In the Name column, type
    BackConnectionHostNames, and then press ENTER.
  6. Right-click BackConnectionHostNames, and then click Modify.
  7. In the Value data box, type the DNS alias, that is used for Azure VM, and then click OK.

    Note Type each host name on a separate line.

    Note If the BackConnectionHostNames registry entry exists as a REG_DWORD type, you have to delete the BackConnectionHostNames registry entry.
  8. Exit Registry Editor, and then restart the BC instance.

After that it started working as it planned.

Hope it will help you and happy sysadmin day!

Comments

*This post is locked for comments