Asp.net

有沒有辦法使用轉換將新部分“插入”到 Web.Config 中?

  • May 17, 2014

在我的 Web.Config 我有以下

 <system.webServer>

   <modules>
      **some code**
   </modules>
   <handlers>
      **some code**    
   </handlers>

 </system.webServer>

如何對其進行轉換,以便將“安全”的新子部分注入“system.webServer”?到目前為止,我嘗試和搜尋的一切都失敗了。

我想要的如下所示:

 <system.webServer>

   <modules>
      **some code**
   </modules>
   <handlers>
      **some code**    
   </handlers>

   <security>
     <ipSecurity allowUnlisted="false" denyAction="NotFound">
       <add allowed="true" ipAddress="10.148.176.10" />
     </ipSecurity>
   </security>

 </system.webServer>

找到了有效的解決方案。在我的 Web.Azure.Config 文件中,我必須添加以下內容:

 <system.webServer>
   <security xdt:Transform="Insert">
     <ipSecurity allowUnlisted="false" denyAction="NotFound">
       <add allowed="true" ipAddress="10.148.176.10" />
     </ipSecurity>
   </security>
 </system.webServer>

我在發布問題之前嘗試了這個,但由於 Web.Config 的另一部分中的拼寫錯誤,它出錯了。

引用自:https://stackoverflow.com/questions/23709851