我有一個Azure的Web應用程序配置爲用於非PROD環境中的web.config基本身份驗證,如下圖所示:Azure Web App - 通過applicationHost.xdt添加基本身份驗證?
<configSections>
<section name="basicAuth" type="Devbridge.BasicAuthentication.Configuration.BasicAuthenticationConfigurationSection" />
</configSections>
<basicAuth allowRedirects="true">
<credentials>
<add username="username" password="password"/>
</credentials>
</basicAuth>
<system.webServer>
<modules>
<add name="MyBasicAuthenticationModule" type="Devbridge.BasicAuthentication.BasicAuthenticationModule"/>
</modules>
<!-- the rest of the web.config follows -->
一切工作正常,但每當我們做了部署PROD與改變web.config中,需要手動更改文件才能禁用基本身份驗證(如上所述,我們僅在非prod上需要它)。
所以我想知道 - 有沒有辦法使用applicationHost.xdt文件進行基本身份驗證?由於這是一個不經常更改的文件,它會使我們的生活更輕鬆。
我已經檢查IIS管理器擴展,但沒有看到任何東西,讓我來完成這項工作。任何提示都表示讚賞!
更新 - 加入我的web.config(我想和applicationHost.xdt更新)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="^OFF$"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
謝謝。我嘗試部署提到applicationHost.xdt(順便說一句,這是一個PHP應用程序,而不是.NET,我們不使用VS,但直接與GitHub集成進行部署)。我收到下面的錯誤 - 「Config section'system.webServer/modules'already defined。Sections must only only once once per config file。」,但我沒有在web.config中定義模塊部分(請參閱q)。 –
忽略我對你的情況的誤解。根據您最近更新的內容,您是否意味着您正試圖在'applicationHost.xdt'文件中添加URL重寫規則以禁用基本身份驗證?如果是這樣,有一個關於[重定向http流量到https]的xdt轉換示例(https://github.com/projectkudu/kudu/wiki/Xdt-transform-samples),您可以參考它。 –
此外,您可以在網絡應用程序的「開發工具」>「擴展」刀片下的Azure門戶上安裝名爲「將HTTP重定向至HTTPS」的站點擴展,或安裝[將HTTP重定向至HTTPS](http://www.siteextensions .net/packages/RedirectHttpToHttps /)擴展名通過KUDU。 –