Sitefinity博客URL配置:如何将文章分类名称纳入URL?
Hey there, let's sort out this URL configuration issue you're running into. I've dealt with similar problems using Telerik/Sitefinity's URL providers before, so here's what's going on and how to fix it:
Why Your Current Attempts Aren't Working
- When you used
/[Category]/[UrlName], you got that weirdTelerik.OpenAccess.TrackedList%601[System.Guid]string becauseCategoryis actually a collection of categories (TrackedList is OpenAccess's way of handling related items), not a single category. Calling it directly just outputs the collection's type name instead of the category title. - Using
/[Category.Title]/[UrlName]threw an error for the same reason: theCategorycollection doesn't have aTitleproperty—only individual category items do.
Correct Way to Include Category Name in URLs
Assuming your content items (like blog posts or news) have a primary category (most setups do), use the PrimaryCategory property instead, which points to the single main category for the item. Here's the correct URL pattern:
/[PrimaryCategory.Title]/[UrlName]
If you prefer a SEO-friendly, cleaned-up version of the category name (instead of the raw title which might have spaces/special characters), use the category's UrlName property instead:
/[PrimaryCategory.UrlName]/[UrlName]
Finding Available Parameters for URL Patterns
There's no single "official cheat sheet" that lists every possible parameter, but here's how to find all valid properties you can use:
- Go to your CMS backend (e.g., Sitefinity) and navigate to the content type you're working with (e.g., Blog Posts, News Items).
- Open the Field Definitions for that content type. Every public property (including related fields like categories, authors, etc.) is fair game for URL patterns.
- For related items (like categories), you can drill into their properties using dot notation—e.g.,
PrimaryCategory.Title,PrimaryCategory.Description,Author.FullName, etc.
If you need to handle multi-category items (where an item has multiple categories and you want to include one in the URL), you'll likely need to write a custom URL provider class instead of relying on the built-in pattern. But for most single-category use cases, the PrimaryCategory approach works perfectly.
内容的提问来源于stack exchange,提问作者Randy Hall

