Debug trong Sitecore quan trọng hơn nhiều so với các hệ thống .NET bình thường, vì Sitecore có pipeline phức tạp, caching, config patching, và nhiều module chạy nền.
Hôm nay bạn sẽ học cách debug chuẩn trong môi trường CM/CD, bao gồm pipeline, controller, rendering, scheduled tasks, và xConnect.
Trong Visual Studio:
Khi build, Visual Studio tạo file .pdb.
Đảm bảo thư mục website (CM/CD) dùng đúng file build từ solution của bạn.
Sitecore chạy dưới w3wp.exe, nên để debug:
Nếu không → attach sẽ bị blocked.
Chọn:
Nếu có nhiều app pool:
CM dùng: sc.dev.local
CD dùng: sc.cd.dev.local
Identity dùng: identityserver.dev.local
Đặt breakpoint trong:
Mở trang có controller rendering → reload → Visual Studio sẽ bắt breakpoint.
Chắc chắn 1 trong các lỗi:
Code chưa build vào đúng folder webroot
Symbol load chưa đúng (.pdb mismatch)
Attaching sai w3wp instance
App pool đang chạy dưới chế độ 32-bit nhưng bạn build 64-bit hoặc ngược lại
Debugger không load symbol
Kiểm tra trong VS:Debug → Windows → Modules → search your DLL → Load Symbols
View Rendering không có controller, nhưng bạn vẫn debug logic thông qua:
Model Builders
Glass Mapper
Pipeline RenderField
Custom HTML Helpers
Đặt breakpoint ở:
Ngoài ra, trong .cshtml bạn có thể debug bằng:
⚠️ Chỉ dùng ở local — KHÔNG bao giờ commit dòng này.
Sitecore pipelines chạy trong nhiều thời điểm: Render Layout, MVC Routing, Authentication, Indexing.
Vị trí:
Chỉ cần đặt breakpoint trong processor:
Reload trang → Visual Studio sẽ bắt vào.
Sitecore Scheduled Task chạy qua:
Hoặc bạn có thể chạy thủ công:
Breakpoint trong class task runner sẽ hoạt động bình thường.
Đặt breakpoint trong:
Chạy lệnh reindex:
Debugger sẽ bắt.
Trong Controller Rendering:
Đặt breakpoint → load page.
Nếu logic personalization không chạy, kiểm tra:
preprocessRequestBreakpoint trong:
Đặt breakpoint trong custom rule:
Load page → customize rule triggered.
Nếu bạn làm Sitecore XP:
Attach debugger vào xconnect service:
Breakpoint trong:
Trong Visual Studio Immediate Window:
Xem realtime logs.
Dùng để xem:
Pipeline
View rendering
Layout resolution
Debug hiệu năng và memory leak.
Tạo một Controller Rendering → đặt breakpoint → attach debugger → reload trang → bắt lỗi.
Viết 1 pipeline processor → đặt breakpoint → chạy thử.
Debug Glass Mapper model binding bằng cách đặt breakpoint trong class mapping.