2011-03-13 124 views
4

如何使用web.config轉換將域屬性包含在我的製作中web.configASP.NET Web.Config轉換問題

我在我的基地web.config以下。

<authentication mode="Forms"> 
    <forms loginUrl="~/Account/Login.aspx" timeout="2880" /> 
</authentication> 

我曾嘗試使用我的web.prod.config以下,但是當我發佈項目不添加屬性。

<authentication mode="Forms" xdt:Transform="Replace"> 
    <forms loginUrl="~/Account/Login.aspx" timeout="2880" domain=".mydomain.com" /> 
</authentication> 

我想輸出爲以下內容。

<authentication mode="Forms"> 
    <forms loginUrl="~/Account/Login.aspx" timeout="2880" domain=".mydomain.com"/> 
</authentication> 
+0

這與你的問題沒有任何關係,而是域名確實是'=「。mydomain.com」'而不是'=「mydomain.com」'...應該在那裏的時間段? – Kiril 2011-03-13 16:32:59

+1

謝謝,是的,點應該在那裏,這將迎合子域,但很多謝謝。 – Kevin 2011-03-25 08:31:15

回答

6

其中這兩個應該工作(未經測試,而是基於Microsoft's documentation):

<system.web> 
    <authentication mode="Forms" xdt:Transform="Replace" xdt:Locator="Match(forms)"> 
    <forms loginUrl="~/Account/Login.aspx" timeout="2880" domain=".mydomain.com" /> 
    </authentication> 
</system.web> 

<system.web> 
    <authentication mode="Forms"> 
    <forms domain=".mydomain.com" xdt:Transform="SetAttributes(domain)" /> 
    </authentication> 
</system.web> 
+0

對此延遲迴復。我會在今天晚上嘗試一下你的解決方案,讓你知道。非常感謝您的幫助。 – Kevin 2011-03-25 08:31:48

+2

你可以使用這個工具測試配置轉換:http://webconfigtransformationtester.apphb.com/ – friism 2011-09-14 15:50:32

+1

此外,這需要在 kmdsax 2014-04-02 20:53:56

3

沒有看到全部的配置我不能肯定這會工作,但我會嘗試添加一個定位器確保它抓住那條線並進行變革。

因此,而不是隻是

<authentication mode="Forms" xdt:Transform="Replace"> 

將在這條道路符合這樣的事

嘗試

<authentication mode="Forms" xdt:Transform="Replace" xdt:Locator="Match(mode)"> 

這將明確在了XPath拿起一個auth節點,其中, mode = Forms,它應該產生1並且只有1匹配到變換引擎並進行替換。

如果這不起作用,我會倒過來看看它是否可以轉換(我懷疑),通過改變loginUrl來轉換它,看看它是否出現在另一端。

你有可能在某個地方得到一個轉換錯誤,它只是不適用。

+0

抱歉,對此延遲迴復。我會在今天晚上嘗試一下你的解決方案,讓你知道。非常感謝您的幫助。 – Kevin 2011-03-25 08:32:18