November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
Hi,
You need to set UseTrailingSlash.
Something like:
var routingOptions = ServiceLocator.Current.GetInstance<RoutingOptions>();
routingOptions.UseTrailingSlash = false;
in an Initialization Module or Application_Start should work.
/Jake
I set it in an Initialization Module:
/// <summary>
/// Set up custom routes
/// </summary>
[InitializableModule]
[ModuleDependency(typeof(ServiceContainerInitialization))]
public class RoutingInitialization : IInitializableModule
{
private static bool _initialized;
public void Initialize(InitializationEngine context)
{
if (_initialized || context.HostType != HostType.WebApplication)
return;
RouteTable.Routes.LowercaseUrls = true;
RouteTable.Routes.AppendTrailingSlash = false;
RouteTable.Routes.MapRoute("Sitemap without path", "sitemap.xml", new { controller = "XmlSitemap", action = "Index" });
RouteTable.Routes.MapRoute("Sitemap with path", "{path}sitemap.xml", new { controller = "XmlSitemap", action = "Index" });
RouteTable.Routes.MapRoute("Sitemap with language", "{language}/sitemap.xml", new { controller = "XmlSitemap", action = "Index" });
RouteTable.Routes.MapRoute("Sitemap with language and path", "{language}/{path}sitemap.xml", new { controller = "XmlSitemap", action = "Index" });
RouteTable.Routes.MapRoute("Robots", "robots.txt", new { controller = "Robots", action = "Robots" });
_initialized = true;
}
public void Uninitialize(InitializationEngine context)
{
}
I would like to never have the trailing slash in my URLs. I can remove it with redirects, and with routing settings. But I am having trouble coming up with a good way to remove it when I am generating Urls that wiull appear on the page. There seems to be several different ways to accomplish getting Urls on the page, and I need to account for all of them (Url Resolver, Url Extension methods, UrlHelper extension methods, etc...) Additionally, in these cases I seem to need to get rid of it with string replcaement, which just feels dirty. Is there a more centralized way to accomplish this?