【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 访问其应用服务。
如使用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>
参考资料
部署App Service: https://docs.azure.cn/zh-cn/app-service/deploy-zip?tabs=cli
【Azure App Service】通过Visual Studio部署Azure App Service 遇见 401 'Unauthorized'错误的更多相关文章
- 【Azure Developer】使用Microsoft Graph API创建用户时候遇见“401 : Unauthorized”“403 : Forbidden”
问题描述 编写Java代码调用Mircrosoft Graph API创建用户时,分别遇见了"401 : Unauthorized"和"403 : Forbidden&q ...
- 【翻译】使用Visual Studio在Azure上部署Asp.Net Core Web应用
配置运行环境 Install the latest Azure SDK for Visual Studio. The SDK installs Visual Studio if you don't a ...
- Visual Studio 2013发布Cloud Service至Azure China
Visual Studio 2013发布Cloud Service至Azure China <Windows Azure Platform 系列文章目录> 之前有很多网友询问我如何通过VS ...
- 微软加速Visual Studio和Azure DevOps 云升级
在 2018 微软技术暨生态大会(Microsoft Tech Summit)上,微软宣布围绕 Visual Studio 和 Visual Studio Code 开发平台提供一系列新功能与服务,并 ...
- 如何通过Visual Studio发布Azure应用程序
发布 Azure 云服务 使用 Azure Tools for Visual Studio,可以直接从 Visual Studio 将云服务发布到 Azure. 在发布 Azure 云服务之前,必须已 ...
- 用Xamarin和Visual Studio编写iOS App
一说开发 iOS app,你立马就会想到苹果的开发语言 Objective C/Swift 和 Xcode.但是,这并不是唯一的选择,我们完全可以使用别的语言和框架. 一种主流的替换方案是 Xamar ...
- Smobiler 4.4 更新预告 Part 2(Smobiler能让你在Visual Studio上开发APP)
Hello Everybody,在Smobiler 4.4中,也为大家带来了新增功能和插件(重点,敲黑板). 新增功能: 1, 企业认证用户可设置路由(即客户端可根据不同的IP地址访问不同的服务器组) ...
- Smobiler 4.4 更新预告 Part 1(Smobiler能让你在Visual Studio上开发APP)
在4.4版本中,大家对产品优化的一些建议和意见进行了相应的优化和修复,同时,还新增了一些令人激动的功能和插件. 下面先为大家介绍4.4版本中Smobiler的优化和修复: 优化 1, PageView ...
- 【Azure 应用服务】Azure Mobile App (NodeJS) 的服务端部署在App Service for Windows中出现404 Not Found -- The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
问题描述 使用NodeJS的后端应用,开发一个Mobile App的服务端,手机端通过REST API来访问获取后端数据.在本地编译好后,通过npm start启动项目,访问效果如下: 但是,当把项目 ...
- Azure China (3) 使用Visual Studio 2013证书发布Cloud Service至Azure China
<Windows Azure Platform 系列文章目录> 之前有很多网友询问我如何通过VS发布Cloud Service至Azure China,这里我专门写篇文章,给大家详细介绍下 ...
随机推荐
- 一次OOM事故的学习过程
事故过程 周二下午得到消息, 希望帮忙分析dump文件. 告知dump大小为42G大小. 一般机器没这么大的内存进行处理. 建议现场上传到百度云盘, 然后我这边进行下载. 时间进度为: 11.57创建 ...
- 谈JVM参数GC线程数ParallelGCThreads合理性设置
作者:京东零售 刘乐 导读:本篇文章聚焦JVM参数GC线程数的合理配置,从ParallelGCThreads参数含义.参数设置,到参数实验以及修改意见进行解析. 1. ParallelGCThread ...
- 【JS 逆向百例】某音 X-Bogus 逆向分析,JSVMP 纯算法还原
声明 本文章中所有内容仅供学习交流使用,不用于其他任何目的,不提供完整代码,抓包内容.敏感网址.数据接口等均已做脱敏处理,严禁用于商业用途和非法用途,否则由此产生的一切后果均与作者无关! 本文章未经许 ...
- 【JS 逆向百例】某网站加速乐 Cookie 混淆逆向详解
声明 本文章中所有内容仅供学习交流,抓包内容.敏感网址.数据接口均已做脱敏处理,严禁用于商业用途和非法用途,否则由此产生的一切后果均与作者无关,若有侵权,请联系我立即删除! 逆向目标 目标:加速乐加密 ...
- 6.4 Windows驱动开发:内核枚举DpcTimer定时器
在操作系统内核中,DPC(Deferred Procedure Call)是一种延迟执行的过程调用机制,用于在中断服务例程(ISR)的上下文之外执行一些工作.DPC定时器是基于DPC机制的一种定时执行 ...
- 性能暴增70%!AMD线程撕裂者RPO 7000将于10月19日发布: 96核心Zen 4史无前例
据wccftech最新报道,AMD的下一代Ryzen Threadripper(线程撕裂者)PRO 7000"Storm Peak"CPU将于10月19日作为终极工作站解决方案亮相 ...
- DevToys(开发工具) v1.0.2.1
从事开发工作的朋友们千万不要错过了!今天为大家带来的这款软件可以说是开发人员的必备工具,它就是DevToys软件!DevToys中包含了许多强大实用的开发工具,能够帮助用户将程序开发变得更加简单大大降 ...
- 【STL源码剖析】string类模拟实现 了解底层-走进底层-掌握底层【超详细的注释和解释】
文章目录 博主对大家的话 前言 实现过程一些要注意的点 STL中string类模拟实现 尾声 博主对大家的话 从今天开始,STL源码剖析的专栏就正式上线了!其实在很多人学习C++过程中,都是只学习一些 ...
- CF813E Army Creation 题解
题目链接:CF 或者 洛谷 并不是很难的题,关于颜色数量类问题,那么很显然,沿用经典的 "HH的项链" 思想去思考问题.由于涉及到了 \(k\) 个数的限制,我们观察到如果一个数在 ...
- 零基础入门Vue之窥探大法——计算与侦听
前言 在 上一小节 我介绍了我学习vue入门 插值语法 的过程. 在本篇,我将记录我对vue的 计算属性和侦听器 的学习记录 注:本篇对于"侦听"和"监听"是一 ...