failed with HTTP status code 'Unauthorized'.

Jassim Al Rahma 1,571 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.
3,877 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,807 questions
0 comments No comments
{count} votes

4 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. 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

  3. Grmacjon-MSFT 18,216 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


  4. Matthew Hess 0 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.
    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.