2012-08-08 11 views
37

मेरे पास कुछ आईआईएस फिर से लिखने वाले नियम हैं जिन्हें मैं पर्यावरण से बदलना चाहता हूं। विकास पुनर्लेखन नियम तो web.test.config फ़ाइल मेरे पास है के अंत में, web.config फ़ाइल में हैं:वेब.config में आईआईएस रीराइट नियमों को बदलना

<appSettings> 
     ...Some app settings tranforms here 
    </appSettings> 
    <system.webserver> 
      <rewrite xdt:Transform="Replace"> 
       <rules> 
       ... rules here 
       </rules> 
      </rewrite> 
      </system.webserver> 
     </configuration> 

मेरे एप्लिकेशन सेटिंग तब्दील हो रहे हैं जब मैं परीक्षण करने के लिए तैनात है, लेकिन आईआईएस पुनर्लेखन द्वारा नियम नहीं हैं। मैं उम्मीद कर रहा था कि पूरे <rewrite> सेक्शन को ट्रांसफॉर्म फ़ाइल में से एक के साथ प्रतिस्थापित किया जाएगा (http://msdn.microsoft.com/en-us/library/dd465326.aspx के अनुसार), लेकिन कुछ भी नहीं बदल रहा है।

मैं भी अलग-अलग नियमों पर xdt:Transform="Replace" xdt:Locator="Match(name)"> डालने की कोशिश की है:

<rule name="Test rule" stopProcessing="true" xdt:Transform="Replace" xdt:Locator="Match(name)"> 

लेकिन फिर से इस कोई फर्क नहीं पड़ता।

क्या वेब.config में पुनर्लेखन नियमों को प्रतिस्थापित करना भी संभव है और यदि हां, तो मुझे क्या याद आ रही है?

उत्तर

0

system.webServer के पुनर्लेखन अनुभाग को बदलना संभव है। मुझे शुरुआत में एक ही समस्या थी और मुझे एहसास हुआ कि मैंने अनजाने में system.web के तहत गलत तरीके से पुनर्लेखन नोड रखा था। हालांकि यह आपके द्वारा प्रदान की गई सीमित स्निपेट के आधार पर आपकी समस्या की तरह नहीं दिखता है, फिर भी मुझे संदेह होगा कि आपकी समस्या ट्रांसफ़ॉर्म फ़ाइल में नोड प्लेसमेंट से संबंधित है।

यहाँ मेरी Web.Debug.config ऐसा दिखाई देता है (और इस संस्करण एक डीबग बिल्ड पर सही Web.config लिख रहा है):

<?xml version="1.0"?> 

<!-- 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 atrribute "name" that has a value of "MyDB". 

    <connectionStrings> 
     <add name="MyDB" 
     connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
     xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> 
    </connectionStrings> 
    --> 
    <system.web> 
    <!-- 
     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> 
    <system.webServer> 
    <rewrite xdt:Transform="Replace"> 
     <rules> 
     <clear/> 
     <rule name="Canonical Hostname"> 
      <!-- Note that I have stripped out the actual content of my rules for the purposes of posting here... --> 
     </rule> 
     </rules> 
    </rewrite> 
    </system.webServer> 
</configuration> 
38

मैं किसी भी पुनर्लेखन नियम नहीं था जैसा कि मेरे मुख्य web.config, प्रतिस्थापन परिवर्तन काम नहीं किया था।

<system.webServer> 
<rewrite xdt:Transform="Insert"> 
    <rules> 
    <rule name="CanonicalHostNameRule1"> 
     <match url="(.*)" /> 
     <conditions> 
     <add input="{HTTP_HOST}" pattern="^www\.mysite\.com$" negate="true" /> 
     </conditions> 
     <action type="Redirect" url="http://www.mysite.com/{R:1}" /> 
    </rule> 
    </rules> 
</rewrite> 
</system.webServer> 
0

एक चाल का उपयोग मैं कार्रवाई एक नाम
तो मेरी बदलने सिर्फ निम्नलिखित

<system.webServer> 
<rewrite> 
    <rules> 

    <rule name="RedirecttoWWW" enabled="true" > 
     <match url="(.*)" /> 
     <conditions> 
     <add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" /> 
     </conditions> 
     <action name="AddWWW" type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" /> 
    </rule> 

    </rules> 
</rewrite> 

ऊपर के उदाहरण है की तरह xdt:Transform="SetAttributes" xdt:Locator="Match(name)" जोड़ने देना है: मैं सफलतापूर्वक बदलने सम्मिलित करें, नीचे के रूप में प्रयोग किया जाता है सभी अनुरोधों का www जोड़ने के लिए

------- अद्यतन -----

सिर्फ एक अद्यतन कार्रवाई करने के लिए नाम जोड़ने के रूप में तो मैं निम्नलिखित

<system.webServer> 

     <rule name="RedirecttoWWW" enabled="true" xdt:Transform="RemoveAll" xdt:Locator="Match(name)" > 
     </rule> 
     <rule name="RedirecttoWWW" enabled="true" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)" > 
     <match url="(.*)" /> 
     <conditions> 
      <add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" /> 
     </conditions> 
     <action type="Redirect" url="http://{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" /> 
     </rule> 
    </rules> 
    </rewrite> 
    </system.webServer> 
6

पुनर्लेखन खंड पर पहले मेरे लिए अजीब तरह से काम किया जब रिलीज कॉन्फ़िगरेशन, त्रुटियों और वर्गों प्रदर्शित नहीं हो बनाने के रूप में कोड अद्यतन चाहते थे काम नहीं करेगा बिलकुल। इस तरह मैंने इसे हल किया।

Microsoft (R) का निर्माण इंजन संस्करण 12.0.31101.0

Microsoft .NET फ्रेमवर्क, संस्करण 4.0.30319.0

संपादित इस के साथ के बारे में खिलवाड़ करने के बाद मैं महसूस किया कि फिर से लिखने टैग होने एक ऐसे सर्वर पर जिसमें रीराइट प्लगइन नहीं है, वेबसर्वर को एक त्रुटि लौटाती है।मैं सर्वर और स्थानीय शहरी मशीन पर विभिन्न विन्यास wan't तो ठीक है:

अन-बदल web.config केवल एक टैग की जरूरत है और एक बुनियादी विहित होस्ट नाम नियम

के लिए web.config.release में
<configuration> 
<system.webServer> 
     <rewrite xdt:Transform="Insert"> 
      <rules> 
       <rule name="CanonicalHostNameRule" xdt:Transform="Insert"> 
        <match url="(.*)" /> 
        <conditions> 
         <add input="{HTTP_HOST}" pattern="^www\.host\.com$" negate="true" /> 
        </conditions> 
        <action type="Redirect" url="http://www.host.com/{R:1}" /> 
       </rule> 
      </rules> 
     </rewrite> 
</system.webServer> 
</configuration> 

कार्रवाई सभी लेकिन फिर से लिखने के टैग पर एक नाम की आवश्यकता नहीं थी xdt की जरूरत है: रूपांतरण = "डालें"

जाहिर है अगर आप इसे अपने स्थानीय मशीन रूप में अच्छी तरह पर चाहते हैं, यह एक अद्यतन के बजाय की आवश्यकता होगी।

संबंधित मुद्दे