Skip to content

Commit a4b449d

Browse files
committed
Introduced new MapTopicSitemap() extension method
Normally, the sitemap will be routed using the standard route—e.g., as supported by `MapDefaultControllerRoute()`. If that isn't being used, for some reason, the `MapTopicSitemap()` method provides a convenience method for establishing a specific route for the sitemap. Currently, this hardcodes the route to `/Sitemap`. In the future, we may choose to extend that to provide a variable path, but that's not an immediate priority.
1 parent 84c054f commit a4b449d

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

OnTopic.AspNetCore.Mvc.Host/Startup.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,8 @@ public static void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
112112
| Configure: MVC
113113
\-----------------------------------------------------------------------------------------------------------------------*/
114114
app.UseEndpoints(endpoints => {
115-
endpoints.MapControllerRoute(
116-
name: "default",
117-
pattern: "{controller}/{action=Index}/"
118-
);
119115
endpoints.MapTopicRoute("Web");
116+
endpoints.MapTopicSitemap();
120117
endpoints.MapControllers();
121118
});
122119

OnTopic.AspNetCore.Mvc/ServiceCollectionExtensions.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,25 @@ public static void MapImplicitAreaControllerRoute(this IEndpointRouteBuilder rou
209209
public static void MapImplicitAreaControllerRoute(this IEndpointRouteBuilder routes) =>
210210
routes.MapDynamicControllerRoute<TopicRouteValueTransformer>("{area:exists}/{action=Index}");
211211

212+
/*==========================================================================================================================
213+
| EXTENSION: MAP TOPIC SITEMAP (IENDPOINTROUTEBUILDER)
214+
\-------------------------------------------------------------------------------------------------------------------------*/
215+
/// <summary>
216+
/// Adds the <c>Sitemap/{action=Index}</c> endpoint route for the OnTopic sitemap.
217+
/// </summary>
218+
/// <remarks>
219+
/// For most implementations, this will be covered by the default route, such as that implemented by the standard <see
220+
/// cref="ControllerEndpointRouteBuilderExtensions.MapDefaultControllerRoute(IEndpointRouteBuilder)"/> method that ships
221+
/// with ASP.NET. This extension method is provided as a convenience method for implementations that aren't using the
222+
/// standard route, for whatever reason, and want a specific route setup for the sitemap.
223+
/// </remarks>
224+
public static ControllerActionEndpointConventionBuilder MapTopicSitemap(this IEndpointRouteBuilder routes) =>
225+
routes.MapControllerRoute(
226+
name: "TopicSitemap",
227+
pattern: "Sitemap/{action=Index}",
228+
defaults: new { controller = "Sitemap" }
229+
);
230+
212231
/*==========================================================================================================================
213232
| EXTENSION: MAP TOPIC REDIRECT (IENDPOINTROUTEBUILDER)
214233
\-------------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)