gpt4 book ai didi

azure - 如何: Password Protect Azure App service

转载 作者:行者123 更新时间:2023-12-02 22:54:31 24 4
gpt4 key购买 nike

我有一个托管在 Azure 应用服务中的网站。 azure 中是否有任何选项,以便我可以在网站上设置密码。理想情况下无需更改网站代码。

只需一个基本密码或用户名和密码,不需要是google或facebook登录或AD登录。

这是一个基于 .net 的网站,我已经看到了一些执行此操作的选项,但这意味着我必须以某种方式更改网站的代码。

当然,有了所有复杂的云技术,我可以进入门户并在服务器级别设置密码吗? - 或者是对应用程序进行某种更改的唯一方法?

最佳答案

可以通过 applicationHost.xdt 中的某些设置为 Azure Web Apps 启用基本身份验证。您可以在启动 Web 应用程序时加载此文件中的一些模块。

步骤:

  • 导航到 Azure 门户中的 Web 应用
  • 在左侧菜单中,搜索标题开发工具,然后选择高级工具 (Kudu)
  • 使用调试控制台 > CMD 工具导航至 WebApp 目录:\home\site
  • 创建一个名为:applicationHost.xdt的文件
  • 粘贴以下内容:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location path="%XDT_SITENAME%" xdt:Locator="Match(path)">
<system.webServer>
<rewrite xdt:Transform="InsertIfMissing">
<allowedServerVariables xdt:Transform="InsertIfMissing">
<add name="RESPONSE_WWW_AUTHENTICATE" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
</allowedServerVariables>
<rules xdt:Transform="InsertIfMissing">
<rule name="BasicAuthentication" stopProcessing="true" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)">
<match url=".*" />
<conditions>
<add input="{HTTP_AUTHORIZATION}" pattern="^Basic dXNlcjpwYXNzd29yZA==" ignoreCase="false" negate="true" />
</conditions>
<action type="CustomResponse" statusCode="401" statusReason="Unauthorized" statusDescription="Unauthorized" />
<serverVariables>
<set name="RESPONSE_WWW_AUTHENTICATE" value="Basic realm=Project" />
</serverVariables>
</rule>
</rules>
</rewrite>
</system.webServer>
</location>
</configuration>
  • 根据您的喜好更改基本身份验证(示例中的默认值为:用户:密码)
  • 确保 web.config 重写规则不包含 <clear />因为这将从 applicationHost.xdt 文件中删除效果
  • 保存文件并停止并启动您的 WebApp(简单的重新启动不足以足够)

注释:

  • 不确定这是否适用于基于 Linux 的 WebApps..
  • 您可以使用 FTP 将此步骤添加到您的部署管道中
  • 更新:我在辅助 Web 应用程序插槽上使用 applicationHost.xdt 时注意到它存在问题。似乎只有主插槽可以工作。

PS: Cross-post from my answer here.

关于azure - 如何: Password Protect Azure App service,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61588030/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com