2010-07-26 28 views
7

Tôi đã thực hiện một phần cấu hình trong tập tin web.config của tôi có tất cả các quy tắc viết lại như sauMoving IIS7 phần url rewrite ra khỏi file web.config

<rewrite> 
     <outboundRules> 
      <rule name="OutboundRewriteCatalogURL" preCondition="ResponseIsHtml1"> 
       <match filterByTags="A" pattern="^(.*/)Catalog\.aspx\?Catalog=([^=&amp;]+)&amp;(?:amp;)?Title=([^=&amp;]+)$" /> 
       <action type="Rewrite" value="{R:1}ctlg/{R:2}/{R:3}/" /> 
      </rule> 
      <rule name="OutboundRewriteCategoryURL" preCondition="ResponseIsHtml1"> 
       <match filterByTags="A" pattern="^(.*/)ProductList\.aspx\?Catalog=([^=&amp;]+)&amp;(?:amp;)?Category=([^=&amp;]+)&amp;(?:amp;)?Title=([^=&amp;]+)$" /> 
       <action type="Rewrite" value="{R:1}categ/{R:2}/{R:3}/{R:4}/" /> 
      </rule> 
      <rule name="OutboundRewriteFullProductURL" preCondition="ResponseIsHtml1"> 
       <match filterByTags="A, Form, Img" pattern="^(.*/)Product\.aspx\?Catalog=([^=&amp;]+)&amp;(?:amp;)?Category=([^=&amp;]+)&amp;(?:amp;)?Product=([^=&amp;]+)&amp;(?:amp;)?Title=([^=&amp;]+)$" /> 
       <action type="Rewrite" value="{R:1}prd/{R:2}-{R:3}-{R:4}/{R:5}/" /> 
      </rule> 
      <preConditions> 
       <preCondition name="ResponseIsHtml1"> 
        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" /> 
       </preCondition> 
      </preConditions> 
     </outboundRules> 
     <rules> 
      <rule name="RedirectCatalogURL" stopProcessing="true"> 
       <match url="^Catalog\.aspx$" /> 
       <conditions> 
        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> 
        <add input="{QUERY_STRING}" pattern="^Catalog=([^=&amp;]+)&amp;Title=([^=&amp;]+)$" /> 
       </conditions> 
       <action type="Redirect" url="Catalog/{C:1}/{C:2}" appendQueryString="false" /> 
      </rule> 
      <rule name="RewriteCatalogURL" stopProcessing="true"> 
       <match url="^ctlg/([^/]+)/([^/]+)/?$" /> 
       <conditions> 
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
       </conditions> 
       <action type="Rewrite" url="Catalog.aspx?Catalog={R:1}&amp;Title={R:2}" /> 
      </rule> 
      <rule name="RedirectCategoryURL" stopProcessing="true"> 
       <match url="^ProductList\.aspx$" /> 
       <conditions> 
        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> 
        <add input="{QUERY_STRING}" pattern="^Catalog=([^=&amp;]+)&amp;Category=([^=&amp;]+)&amp;Title=([^=&amp;]+)$" /> 
       </conditions> 
       <action type="Redirect" url="categ/{C:1}/{C:2}/{C:3}" appendQueryString="false" /> 
      </rule> 
      <rule name="RewriteCategoryURL" stopProcessing="true"> 
       <match url="^categ/([^/]+)/([^/]+)/([^/]+)/?$" /> 
       <conditions> 
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
       </conditions> 
       <action type="Rewrite" url="ProductList.aspx?Catalog={R:1}&amp;Category={R:2}&amp;Title={R:3}" /> 
      </rule> 
      <rule name="RedirectProductURL" stopProcessing="true"> 
       <match url="^Product\.aspx$" /> 
       <conditions> 
        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> 
        <add input="{QUERY_STRING}" pattern="^Catalog=([^=&amp;]+)&amp;Category=([^=&amp;]+)&amp;Product=([^=&amp;]+)&amp;Title=([^=&amp;]+)$" /> 
       </conditions> 
       <action type="Redirect" url="prd/{C:1}-{C:2}-{C:3}/{C:4}" appendQueryString="false" /> 
      </rule> 
      <rule name="RewriteProductURL" stopProcessing="true"> 
       <match url="^prd/([^/]+)-([^/]+)-([^/]+)/([^/]+)/?$" /> 
       <conditions> 
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
       </conditions> 
       <action type="Rewrite" url="Product.aspx?Catalog={R:1}&amp;Category={R:2}&amp;Product={R:3}&amp;Title={R:4}" /> 
      </rule> 
     </rules> 
    </rewrite> 

của nó rất đẹp và làm việc tốt nhưng tôi không muốn có tất cả những thứ này trong tệp web.config, có cách nào để viết lại cấu hình trong tệp cấu hình bên ngoài không?

Trả lời

5

Bạn có thể chia cấu hình của bạn thành nhiều tập tin và bao gồm những phần vào file web.config chính sử dụng thuộc tính configSource, ví dụ:

web.config:

<system.web> 
    ... 
    <profile configSource="profile.config" /> 
    ... 
    </system.web> 

profile.config:

<profile> 
    <properties> 
    <add name="Name" type="String" /> 
    <add name="Age" type="Int32" /> 
    </properties> 
</profile> 

Xem this blog post hoặc this question để biết thêm thông tin.

+0

Liên kết tới blog của NikhilK bị hỏng, nhưng anh ấy hướng dẫn bạn đến đường dẫn ngược. Đây là liên kết hoạt động từ kho lưu trữ: http://wayback.archive.org/web/20110917015737/http://www.nikhilk.net/Entry.aspx?id=158 – yzorg

Các vấn đề liên quan