Back To Home

Name: Ngày 12: Config patch file trong App_Config/Include

1. Tạo file config patch

Trong App_Config/Include, bạn tạo một file đặt tên theo chuẩn:

 
Project.FeatureName.Settings.config

Ví dụ:

 
App_Config/Include/MyProject/MyProject.Content.config

2. Cấu trúc chuẩn của một patch file

Một patch file không được thay thế toàn bộ file gốc, mà chỉ ghi đè (patch) một phần thông qua namespace Sitecore.Configuration.

Cấu trúc chuẩn:

 
<?xml version="1.0"?> <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> <sitecore> <!-- Ví dụ: Thay đổi giá trị một setting --> <setting name="MyCustomSetting"> <patch:attribute name="value">New Value</patch:attribute> </setting> </sitecore> </configuration>

3. Các kiểu patch phổ biến

3.1. Thay đổi attribute

 
<patch:attribute name="value">true</patch:attribute>

3.2. Ghi đè toàn bộ node

 
<yourNode patch:replace="*"> <!-- nội dung mới --> </yourNode>

3.3. Thêm node mới

 
<yourParentNode> <yourNewNode patch:after="*"> value </yourNewNode> </yourParentNode>

3.4. Xóa node

 
<yourParentNode> <yourNodeToRemove patch:delete="*"/> </yourParentNode>

✔ Ví dụ thực tế (Sitecore 9+/10):

Thêm processor vào pipeline

 
<pipelines> <httpRequestBegin> <processor type="MyProject.Pipelines.MyProcessor, MyProject" patch:after="processor[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']"/> </httpRequestBegin> </pipelines>

Thay đổi timeout của session

 
<settings> <setting name="SessionStateTimeout"> <patch:attribute name="value">60</patch:attribute> </setting> </settings>

❗ Lưu ý quan trọng

✓ Phải có xmlns:patch="http://www.sitecore.net/xmlconfig/"
✓ Không được ghi đè toàn bộ file gốc — chỉ patch node cần thiết
✓ Nên đặt config vào thư mục con:

 
App_Config/Include/ProjectName/

✓ Đặt tên file theo thứ tự alphabet nếu cần ưu tiên load (Sitecore load theo thứ tự ABC).
Ví dụ:

 
MyProject.Content.01.config MyProject.Content.02.config

Donald Trump

Để trở thành người chiến thắng, bạn cần biết khi nào là đủ. Đôi khi trong cuộc sống, bạn phải từ bỏ cuộc chiến và chuyển sang mục tiêu mới mang lại hiệu quả hơn

Related Post