【Azure App Service】通过Visual Studio部署Azure App Service 遇见 401 'Unauthorized'错误

简介: 【Azure App Service】通过Visual Studio部署Azure App Service 遇见 401 'Unauthorized'错误

问题描述

最近通过Visual Studio 2022部署Azure App Service的时候,突然遇见了部署失败, 401 Unauthorized错误。

错误消息:

Build started...
1>------ Build started: Project: myapi01, Configuration: Release Any CPU ------
1>myapi01 -> C:\MyCode\44-AppService-ASP.NET\myapi01\bin\Release\net7.0\myapi01.dll
2>------ Publish started: Project: myapi01, Configuration: Release Any CPU ------
myapi01 -> C:\MyCode\44-AppService-ASP.NET\myapi01\bin\Release\net7.0\myapi01.dll
myapi01 -> C:\MyCode\44-AppService-ASP.NET\myapi01\obj\Release\net7.0\PubTmp\Out\
C:\Program Files\dotnet\sdk\7.0.304\Sdks\Microsoft.NET.Sdk.Publish\targets\PublishTargets\Microsoft.NET.Sdk.Publish.MSDeploy.targets(140,5): 
Error : Web deployment task failed. (Connected to the remote computer ("javatest02.scm.chinacloudsites.cn") using the Web Management Service, 
but could not authorize. Make sure that you are using the correct user name and password, that the site you are connecting to exists, 
and that the credentials represent a user who has permissions to access the site.  
Learn more at: https://go.microsoft.com/fwlink/?LinkId=221672#ERROR_USER_UNAUTHORIZED.)
Make sure the site name, user name, and password are correct. If the issue is not resolved, please contact your local or server administrator.
Error details:
Connected to the remote computer ("javatest02.scm.chinacloudsites.cn") using the Web Management Service, but could not authorize. 
Make sure that you are using the correct user name and password, that the site you are connecting to exists, 
and that the credentials represent a user who has permissions to access the site.  
Learn more at: https://go.microsoft.com/fwlink/?LinkId=221672#ERROR_USER_UNAUTHORIZED.
The remote server returned an error: (401) Unauthorized.
Publish failed to deploy.
2>Build failed. Check the Output window for more details.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Build started at 7:10 PM and took 04.863 seconds ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
========== Publish started at 7:10 PM and took 04.863 seconds ==========

非常疑惑,因为在VS中使用的认证是从App Service门户上下载的Publish Profile文件,其中包含的登录的用户名和密码。

那为什么它就不能通过App Service的登录认证了呢?

 

问题解答

因为发布中使用的Publish Profile文件是从Azure 门户上下载,不存在人为错误导致密码错误无法认证。那么就只能从配置方面着手检查:

第一步:查看App Service的基本设置(General Setting)

注:Basic Authentication被设置为 Off。表示通过站点的用户名和密码登录方式已经不可用。 此点正符合部署时遇见的401 Unauthorized问题。

 

第二步: 修改 Basic Authentication为On

再次从VS 2022中部署站点,发布成功。

当然,如果不启用 Basic Authentication,有没有其他可以部署的方式呢?

 

当然可以,使用Azure AD登录认证,也就是我们最常规的使用登录Azure 的账号进行认证。

禁用基本身份验证

一些组织需要满足安全要求,因此宁愿禁用通过 FTP 或 WebDeploy 进行的访问。 这样一来,组织的成员就只能通过 Azure Active Directory (Azure AD) 控制的 API 访问其应用服务。

Link: https://docs.azure.cn/zh-cn/app-service/deploy-configure-credentials?tabs=cli#disable-basic-authentication

如使用az cli命令进行部署:

az cloud set --name AzureChinaCloud
 
az login -u <Azure User Account> -p <Password>
az account set --subscription "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
az webapp deploy --resource-group <group-name> --name <app-name> --src-path <zip-package-path>

 

参考资料

禁用基本身份验证:https://docs.azure.cn/zh-cn/app-service/deploy-configure-credentials?tabs=cli#disable-basic-authentication

部署App Service: https://docs.azure.cn/zh-cn/app-service/deploy-zip?tabs=cli

相关文章
|
2月前
|
人工智能 文件存储 数据中心
Ollama部署本地大模型并通过Infortress APP远程访问保姆级教程
本文介绍如何快速上手本地大模型部署工具Ollama及AI远程访问工具Infortress。通过Ollama,开发者可轻松部署如Llama、Deepseek等主流开源模型,仅需几行命令即可完成安装与运行。结合Infortress,用户能实现对本地大模型的远程访问,支持多设备无缝对接,同时提供便捷的模型切换与知识库管理功能。Infortress更兼具NAS软件特性,成为个人AI数据中心的理想选择。
|
3月前
|
存储 安全 数据安全/隐私保护
【Azure Function App】在Function App中使用System Managed Identity访问Storage Account
本文介绍了如何在Azure Function中使用托管身份(Managed Identity)替代AzureWebJobsStorage连接函数应用到存储账户,以提高安全性并减少Access Key的使用。具体步骤包括:1) 启用系统分配的身份;2) 为函数应用授予存储访问权限,添加必要角色(如Storage Blob Data Contributor);3) 配置`AzureWebJobsStorage__blobServiceUri`参数指定Blob Service Uri。完成后删除旧配置,即可通过Managed Identity访问Storage Account。
126 20
|
2月前
|
安全 Linux 开发工具
【Azure Function】分享把Function App从.NET 6.0升级到.NET 8.0 Isolated的步骤
本文介绍了将Azure Function App从.NET 6.0升级到.NET 8.0 Isolated的步骤。.NET 6.0作为长期支持版本,生命周期至2024年11月结束。为确保持续支持,建议升级至更新版本。升级步骤包括安装.NET 8 SDK、更新Azure Functions Core Tools、修改项目文件目标框架为net8.0、更新兼容的NuGet包、本地测试以及重新发布到Azure。更多详细信息可参考官方文档。
102 9
|
2月前
|
API Go 网络架构
【Azure Logic App】特殊的方法来停止正常步骤无法停止的Workflow Job
本文介绍了一种特殊方法,用于解决标准版Logic App在异常情况下无法正常停止的问题。当点击Cancel按钮报错“WorkflowRunCanNotBeCancelled”时,可通过以下步骤解决:进入Logic App的Kudu页面,定位到`C:\home\site\wwwroot`目录下的`host.json`文件,添加`Jobs.SuspendedJobPartition`和`Jobs.CleanupJobPartition`参数,并以大写格式设置值为`&quot;&lt;WORKFLOWID&gt;:2D&lt;RUNID&gt;&quot;`。调整后可成功停止异常Job
81 18
|
3月前
【Logic App】获取Azure Logic App在执行的标识值 Identifier
本文介绍了如何在Logic App中记录执行标识符以方便问题排查。通过添加一个变量(如RequestTrackingID),将其值设为`workflow()[&#39;run&#39;][&#39;name&#39;]`,可实现将Logic App执行的Identifier与业务数据关联。这样,在排查问题时,可通过日志中的关键信息快速定位对应的Logic App执行记录,提升效率。文中还提供了操作步骤及参考资料,帮助用户更好地理解和实现该方法。
81 10
|
3月前
|
存储 监控 API
【Azure App Service】分享使用Python Code获取App Service的服务器日志记录管理配置信息
本文介绍了如何通过Python代码获取App Service中“Web服务器日志记录”的配置状态。借助`azure-mgmt-web` SDK,可通过初始化`WebSiteManagementClient`对象、调用`get_configuration`方法来查看`http_logging_enabled`的值,从而判断日志记录是否启用及存储方式(关闭、存储或文件系统)。示例代码详细展示了实现步骤,并附有执行结果与官方文档参考链接,帮助开发者快速定位和解决问题。
118 23
|
4月前
|
容器
【Azure Container App】在消耗性的Container App Environmnet中无法查看当时正在使用多少CPU多少实例数的替代方案
在 Azure Container Apps 中使用 Consumption 消耗型环境时,无法通过门户查看当前核心 (CPU) 和实例使用情况。这是因为消耗型工作负载配置文件的设计所致。若需查看使用状态,可使用 az cli 命令 `az containerapp env list-usages` 获取详细信息,包括 Current Cores 数量。文档还提供了参考资料链接以帮助用户深入了解相关命令用法。
85 17
|
4月前
|
网络协议
【Azure App Service】App Service 如何配置私网域名以及证书呢?
本文解答了关于 Azure App Service 如何配置私网域名及证书的问题。App Service 不支持私网域名,自定义域名需配置在公共 DNS 服务器上。文章引用官方文档详细说明了映射自定义 DNS 的步骤,并附带参考资料链接,帮助用户深入了解相关配置方法。
|
4月前
|
存储 安全 开发工具
【Azure Storage Account】利用App Service作为反向代理后续 ---- 隐藏 SAS Token
本文介绍了如何通过App Service作为反向代理,将SAS Token追加到请求URL中,以避免直接在代码或配置文件中存储SAS Token带来的安全性和维护问题。具体步骤包括修改App Service的web.config Rewrite规则,将SAS Token添加到转发的URL中;并在.NET SDK中仅使用不包含SAS Token的Uri进行Blob操作。这样既提高了安全性,也简化了SAS Token的管理。
73 16
Visual Studio 2022 中VLD库如何安装
Visual Studio 2022 中VLD库如何安装
801 1

热门文章

最新文章