failed with HTTP status code 'Unauthorized'.

Jassim Al Rahma 1,596 Reputation points
2023-05-14T19:52:08.6466667+00:00

Hi,

Why I suddenly started getting this error:

/Users/jassim/Projects/OneID/One ID API/Controllers/Account.cs(116,9,116,15): warning CS0162: Unreachable code detected
/usr/local/share/dotnet/sdk/7.0.203/Sdks/Microsoft.NET.Sdk.Publish/targets/PublishTargets/Microsoft.NET.Sdk.Publish.ZipDeploy.targets(55,5): error : The attempt to publish the ZIP file through 'https://oneid.scm.azurewebsites.net/api/zipdeploy' failed with HTTP status code 'Unauthorized'.
    13 Warning(s)
    1 Error(s)

How can I fix it, please?

Thanks,

Jassim

.NET
.NET
Microsoft Technologies based on the .NET software framework.
4,108 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,318 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. moo2u2 46 Reputation points
    2024-04-23T11:14:22.2566667+00:00

    In my case there is a new toggle under "Configuration" which disables "SCM Basic Auth Publishing Credentials" - as it was set to "Off" and I needed to toggle it "On". I discovered this when trying to "Download publish profile" from the Overview tab of the web app, and it failed.

    User's image

    1 person found this answer helpful.
    0 comments No comments

  2. Matthew Hess 5 Reputation points
    2024-09-22T17:02:59.8766667+00:00

    There are several ways to publish an Azure Function to an Azure Function App. This answer applies specifically to publishing via Visual Studio 2022 (screen shots from version `7.9.2)

    As mentioned above, make sure Basic SCM Auth Publishing is set to On and Restart to app. Then try this...

    1. In the Azure Portal, your Azure Function App, Overview, click Get publish profile.
      User's image
    2. In Visual Studio, right-click your function and choose Publish to bring up the publish wizard. Click New Profile and then choose Import Profile
      User's image
    3. Click Next and then Browse... to select the file you downloaded in step 1. Complete the wizard and publish the app. This worked for me.
    1 person found this answer helpful.
    0 comments No comments

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. Grmacjon-MSFT 18,816 Reputation points
    2023-05-17T19:33:05.5966667+00:00

    Hi @Jassim Al Rahma

    We are sorry to hear you're facing this issue. Can you please give us more details about what you were trying to achieve before you got this error?

    There are two separate issues happening here.

    • The first one (warning CS0162: Unreachable code detected):

    The warning message means that you have some code in your file "Account.cs" that is unreachable, meaning it will never be executed. To fix this warning, you need to locate the line number mentioned in the warning (116,9,116,15) and examine the code in that range.

    • The second error message (The attempt to publish the ZIP file through 'https://oneid.scm.azurewebsites.net/api/zipdeploy' failed with HTTP status code 'Unauthorized')

    This error is due to a permission issue. It basically means that the deployment failed because the user account that you are using to publish the ZIP file does not have the necessary permissions to deploy to the specified Azure Web App.

    you can fix this error by making sure the user account that you are using to publish the ZIP file has the necessary permissions to deploy to the Azure Web App. You can do this by checking the deployment credentials for the Azure Web App in the Azure portal and ensuring that the user account that you are using has the necessary permissions.

    Hope that helps. please let us know if you have further questions


  5. Euan Gordon 1 Reputation point
    2025-02-13T10:47:29.9833333+00:00

    Same issue here.

    Made a new function project that does almost nothing, but can't publish it using VS2022.

    In the Azure Portal I have enabled SCM, downloaded a Publish Profile, some info I can gather shown below.

    I don't understand how bad this is, like making a brand new function and wanting to publish it is almost impossible using VS2022. I have managed to publish using the command line only using

     func azure functionapp publish CompassCoreFunctions-Ais-Test
    
    Publish has encountered an error.
    Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details. 
    A diagnostic log has been written to the following location:
    "C:\Users\Euan Gordon\AppData\Local\Temp\tmp5900.tmp"
    
    The attempt to publish the ZIP file through https://compasscorefunctions-ais-test.scm.azurewebsites.net/api/zipdeploy failed with HTTP status code NotFound.
    
    2>Publishing C:\Users\Euan Gordon\source\repos\CompassCore-Functions\CompassAis\obj\Release\net8.0\PubTmp\CompassAis - 20250213104253944.zip to https://compasscorefunctions-ais-test.scm.azurewebsites.net/api/zipdeploy...
    2>C:\Users\Euan Gordon\.nuget\packages\microsoft.azure.functions.worker.sdk\1.16.2\build\Microsoft.Azure.Functions.Worker.Sdk.Publish.ZipDeploy.targets(47,5): Error : The attempt to publish the ZIP file through https://compasscorefunctions-ais-test.scm.azurewebsites.net/api/zipdeploy failed with HTTP status code NotFound.
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.