<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12
      代碼改變世界

      使用Web.Config Transformation配置靈活的配置文件

      2013-11-12 08:08  JustRun  閱讀(5803)  評論(3)    收藏  舉報

      發布Asp.net程序的時候,開發環境和發布環境的Web.Config往往不同,比如connectionstring等。如果常常有發布的需求,就需要常常修改web.config文件,這往往是一件非常麻煩的事情。
      Web.Config Transformation能夠在不同的發布環境下,產生不同的web.config文件,非常方便和實用。

      閱讀目錄:

      一、Web.Config Transformation

      二、一個實際的例子

      三、Web.Config Transformation具體語法

      一. Web.Config Transformation

      項目中有個默認的web.config, 還可以定義格式為web.[name].config文件, 這個配置文件定義的規則, 在發布的時候, 會對web.config文件進行修改。
      默認項目中, 會創建Web.Debug.config和Web.Release.config文件,分別對應于Debug和Release環境。

      blog11

       

      二. 一個實際的例子

      假如我們要常常發布到測試服務器上,測試服務器和開發時候的connectionstring是不同的,看看如何使用Web.Config Transformation來解決這個問題。

      1. 添加Test配置

      菜單Build->Configuration Manager, 就能看到如下的配置窗口, 添加一個新的配置Test.

      blog1

       

      2. 添加Test config Transformation文件

      在web.confg上,點擊右鍵,Add Config Transform, VS就會為剛剛新建的Test配置新增Transformation文件 Web.Test.config

      blog2

       

      blog3

      3. 修改Web.Test.config文件

      下面的Web.Test.config中能夠替換web.config中的connectionstring, 關鍵是這一段

      <add name="MyDB"
              connectionString="Data Source=TestSQLServer;Initial Catalog=MyTestDB;Integrated Security=True"
              xdt:Transform="Replace" xdt:Locator="Match(name)"/>

      xdt:Transform="Replace", 指的是用來做替換操作
      xdt:Locator="Match(name), 指的是匹配規則,這里是匹配name
      意思是用Web.Test.config中的這個配置節用來替換web.config中name為MyDB的配置

      <?xml version="1.0" encoding="utf-8"?>
      
      <!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
      
      <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
        <!--
          In the example below, the "SetAttributes" transform will change the value of
          "connectionString" to use "ReleaseSQLServer" only when the "Match" locator
          finds an attribute "name" that has a value of "MyDB".
          <connectionStrings>
            <add name="MyDB"
              connectionString="Data Source=TestSQLServer;Initial Catalog=MyTestDB;Integrated Security=True"
              xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
          </connectionStrings>
        -->
          <connectionStrings>
            <add name="DefaultConnection"
              connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" providerName="System.Data.SqlClient"
              xdt:Transform="Replace" xdt:Locator="Match(name)"/>
          </connectionStrings>
        <system.web>
          <compilation xdt:Transform="RemoveAttributes(debug)" />
          <!--
            In the example below, the "Replace" transform will replace the entire
            <customErrors> section of your web.config file.
            Note that because there is only one customErrors section under the
            <system.web> node, there is no need to use the "xdt:Locator" attribute.
            <customErrors defaultRedirect="GenericError.htm"
              mode="RemoteOnly" xdt:Transform="Replace">
              <error statusCode="500" redirect="InternalError.htm"/>
            </customErrors>
          -->
        </system.web>
      </configuration>

      4. 檢查發布的結果

      選擇在Test配置下publish網站,你能看到最終的web.config文件,已經實現了替換connection string.

      blog5

       

      三. Web.Config Transformation具體語法

      參考博客 http://www.rzrgm.cn/worksguo/archive/2009/08/29/1556307.html

      1 :locator屬性

      下面有個表,來詳細列舉locator的語法

      (1)Match;

      這里你需要就是在你直接匹配的屬性名。     

      <connectionStrings>
      <add name="Northwind" connectionString="connection string detail"
          providerName="System.Data.SqlClient"
          xdt:Transform="Replace"
          xdt:Locator="Match(name)" />
      </connectionStrings>

      Engine會再你的Web.config中找到匹配name為Norhwind的就用上面的配置文件圖替換。
      (2)Condition
      基于XPath,在Locator中應用有邏輯性的判斷表達式。

       <connectionStrings>
      <add name="Northwind"
          connectionString="connection string detail"
          providerName="System.Data.SqlClient"
          xdt:Transform="Replace"
          xdt:Locator="Condition(@name=’Northwind or @providerName=' System.Data.SqlClient')" />
      </connectionStrings>

      上面就是Name屬性匹配‘Norhwind’的或providerName匹配System.Data.SqlClient的配置文件節點都會被替換。
      (3)XPath
      這個就是直接寫XPath,http://www.w3.org/TR/xpath,這里是XPath的標準

      <location path="c:\MySite\Admin" >
      <system.web xdt:Transform="Replace" xdt:Locator="XPath(//system.web)">
      
      </system.web>
      <location>

      這里你會發現,這里可以寫一些列的表達式。

      2: Transform 屬性

      (1) Replace
      表示所有匹配的節點都是替換

      <assemblies xdt:Transform="Replace">
      <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      </assemblies>

      其實這里描述文件時web.release.config,將要替換的文件時Web.config .
      (2) Remove
      刪除第一匹配的元素。

      <assemblies xdt:Transform="Remove">
      </assemblies>

      (3)RemoveAll

      刪除所有匹配的元素

      <connectionStrings>
      <add xdt:Transform="RemoveAll"/>
      </connectionStrings>

      (4)Insert

      插入從父節點中插入,(authorization中插入<deny users="*" />)

      <authorization>
      <deny users="*" xdt:Transform="Insert"/>
      </authorization>

      (5)SetAttributes

      直接設置Attributes

      <compilation  batch="false"
          xdt:Transform="SetAttributes(batch)">
      </compilation>

      (6)RemoveAttributes
      刪除出Attributes

      <compilation xdt:Transform="RemoveAttributes(debug,batch)">
      </compilation>

      (7)InsertAfter (XPath)
      通過匹配 XPath的表達式的,找到節點,并子節點后面插入 XML

      <authorization>
      <deny users="AName" xdt:Transform="InsertAfter(/configuration/system.web/authorization/ allow[@roles='Admins']") />
      </authorization>

      (8)InsertBefore (XPath)
      通過匹配 XPath的表達式的,找到節點,并子節點前面插入 XML

      <authorization>
      <allow roles=" Admins" xdt:Transform="InsertBefore(/configuration/system.web/authorization/ deny[@users='*'])" />
      </authorization>

      (9)XSLT (filePath)

      可以在外部定義 XSLT文件,來替換Web.cofig文件。

      <appSettings xdt:Transform="XSLT(V:\MyProject\appSettings.xslt)">
      </appSettings>
      主站蜘蛛池模板: 国产精品欧美福利久久| 九九热精品视频在线免费| 欧美成人午夜精品免费福利| 国产精品中文字幕一区| 无码专区一va亚洲v专区在线| 国产精品日韩av在线播放| 色综合欧美亚洲国产| 粉嫩蜜臀av一区二区三区| 国产精品视频一品二区三| 66亚洲一卡2卡新区成片发布| 久青草国产综合视频在线| 精品尤物国产尤物在线看| 精品国产免费人成在线观看| 国产女人喷潮视频免费| 女子spa高潮呻吟抽搐| 国产在线午夜不卡精品影院| 国产精品人成视频免费播放| brazzers欧美巨大| 日韩精品一二三黄色一级| 亚洲永久精品ww47永久入口| 中文 在线 日韩 亚洲 欧美| 久久这里只精品热免费99| 亚洲国产良家在线观看| 国产又色又爽无遮挡免费动态图| 99久久99久久久精品久久| 国产精品国产高清国产一区| 亚洲一区二区三区四区| 亚洲无码精品视频| 精品人妻蜜臀一区二区三区| 一区二区三区国产亚洲网站| 日韩人妻无码一区二区三区| 久久亚洲精品亚洲人av| 在线免费播放av观看| 亚洲国产日韩一区三区| 亚洲av与日韩av在线| 91国在线啪精品一区| 亚洲欧美另类久久久精品播放的| 成人亚洲一区二区三区在线| 性欧美大战久久久久久久| 国产成人精品亚洲精品密奴| 噜噜综合亚洲av中文无码|