[研究][ASP.NET]建立多 Web.Config 組態設定檔 (Multiple Web.Config)
2022-05-12
2022-06-22更新
環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#
如果新增時沒選複製來源,產生的 Web.XXX.Config 內容如下
<?xml version="1.0" encoding="utf-8"?>
<!-- 如需使用 web.config 轉換的詳細資訊,請前往 https://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
在下面的範例中,"SetAttributes" 轉換只會在 "Match" 定位程式找到
值為 "MyDB" 的屬性 "name" 時,才將 "connectionString" 的值變
更為使用 "ReleaseSQLServer"。
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<!--
在下面的範例中,"Replace" 轉換將會取代 web.config 檔案
的整個 <customErrors> 區段。
請注意,因為在 <system.web> 節點之下
只有一個 customErrors 區段,所以不需要使用 "xdt:Locator" 屬性。
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
|
內容填寫請看官方資訊。
發佈 (deploy) 方法
********************************************************************************
2022-06-22 補
如果新作的 Web.Config 是 Debug 用的,請參考 Debug 選項設定新的 Web.Config。
(下圖)在專案 (Project) 上按下滑鼠右鍵,選「屬性」。(注意,別選到 方案 (Solution) 去了)
(完)
相關
ASP.NET Configuration File Hierarchy and Inheritance | Microsoft Docs
https://docs.microsoft.com/en-us/previous-versions/aspnet/ms178685(v=vs.100)?redirectedfrom=MSDN
檔案轉換和變數替代 - Azure Pipelines | Microsoft Docs
https://docs.microsoft.com/zh-tw/azure/devops/pipelines/tasks/transforms-variable-substitution?view=azure-devops&tabs=Classic
轉換 web.config | Microsoft Docs
https://docs.microsoft.com/zh-tw/aspnet/core/host-and-deploy/iis/transform-webconfig?view=aspnetcore-6.0
Transform web.config | Microsoft Docs
https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/transform-webconfig?view=aspnetcore-6.0
使用 Visual Studio ASP.NET Web 部署: Web.config 檔轉換 | Microsoft Docs
https://docs.microsoft.com/zh-tw/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/web-config-transformations
ASP.NET Web Deployment using Visual Studio: Web.config File Transformations | Microsoft Docs
https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/web-config-transformations
Web.config Transformation Syntax for Web Project Deployment Using Visual Studio | Microsoft Docs
https://docs.microsoft.com/en-us/previous-versions/aspnet/dd465326(v=vs.110)













沒有留言:
張貼留言