Skip to content

Commit

Permalink
Merge pull request #7 from oopanuga/trailing_slash_for_path_with_a_dot
Browse files Browse the repository at this point in the history
Trailing slash for path with a dot
  • Loading branch information
oopanuga committed Apr 30, 2016
2 parents f43e8d9 + 373e507 commit 0366765
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
35 changes: 30 additions & 5 deletions SeoPack/Helpers/UrlHelperExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using SeoPack.Url;
using System;
using System.Web;
using SeoPack.Url;
using System.Web.Mvc;
using System.Web.Routing;
using SeoPack.Url.UrlPolicy;
Expand Down Expand Up @@ -38,7 +40,7 @@ public static UrlSeoHelper UnpackSeo(this UrlHelper urlHelper)
/// <returns></returns>
public static string RouteSeoFriendlyUrl(this UrlHelper urlHelper, object routeValues)
{
return new SeoFriendlyUrl(urlHelper.RouteUrl(routeValues)).Value.AbsoluteUri;
return new SeoFriendlyUrl(ToAbsoluteUrl(urlHelper.RouteUrl(routeValues))).Value.AbsoluteUri;
}

/// <summary>
Expand All @@ -51,7 +53,7 @@ public static string RouteSeoFriendlyUrl(this UrlHelper urlHelper, object routeV
/// <returns></returns>
public static string RouteSeoFriendlyUrl(this UrlHelper urlHelper, RouteValueDictionary routeValues)
{
return new SeoFriendlyUrl(urlHelper.RouteUrl(routeValues)).Value.AbsoluteUri;
return new SeoFriendlyUrl(ToAbsoluteUrl(urlHelper.RouteUrl(routeValues))).Value.AbsoluteUri;
}

/// <summary>
Expand All @@ -64,7 +66,7 @@ public static string RouteSeoFriendlyUrl(this UrlHelper urlHelper, RouteValueDic
/// <returns></returns>
public static string RouteSeoFriendlyUrl(this UrlHelper urlHelper, string routeName)
{
return new SeoFriendlyUrl(urlHelper.RouteUrl(routeName)).Value.AbsoluteUri;
return new SeoFriendlyUrl(ToAbsoluteUrl(urlHelper.RouteUrl(routeName))).Value.AbsoluteUri;
}

/// <summary>
Expand All @@ -78,7 +80,21 @@ public static string RouteSeoFriendlyUrl(this UrlHelper urlHelper, string routeN
/// <returns></returns>
public static string RouteSeoFriendlyUrl(this UrlHelper urlHelper, string routeName, object routeValues)
{
return new SeoFriendlyUrl(urlHelper.RouteUrl(routeName, routeValues)).Value.AbsoluteUri;
return new SeoFriendlyUrl(ToAbsoluteUrl(urlHelper.RouteUrl(routeName, routeValues))).Value.AbsoluteUri;
}

/// <summary>
/// Generates a fully qualified Seo friendly URL for the specified route values based on a set
/// of predefined url policies. See <see cref="UrlPolicyConfiguration"/> on configuring url
/// policies.
/// </summary>
/// <param name="urlHelper">The URL helper.</param>
/// <param name="routeName">Name of the route.</param>
/// <param name="routeValues">The route values.</param>
/// <returns></returns>
public static string RouteSeoFriendlyUrl(this UrlHelper urlHelper, string routeName, RouteValueDictionary routeValues)
{
return new SeoFriendlyUrl(ToAbsoluteUrl(urlHelper.RouteUrl(routeName, routeValues))).Value.AbsoluteUri;
}

/// <summary>
Expand Down Expand Up @@ -111,5 +127,14 @@ public static string RouteSeoFriendlyUrl(this UrlHelper urlHelper, string routeN
{
return new SeoFriendlyUrl(urlHelper.RouteUrl(routeName, routeValues, protocol, hostName)).Value.AbsoluteUri;
}

private static string ToAbsoluteUrl(string route)
{
var requestUrl = HttpContext.Current.Request.Url;
return string.Format("{0}://{1}{2}",
requestUrl.Scheme,
requestUrl.Authority,
route);
}
}
}
2 changes: 1 addition & 1 deletion SeoPack/Url/UrlPolicy/Policies/TrailingSlashPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class TrailingSlashPolicy : UrlPolicyBase
{
protected override void ApplyPolicy(UriBuilder uri)
{
if (!uri.Path.EndsWith("/") && !uri.Path.Contains("."))
if (!uri.Path.EndsWith("/")/* && !uri.Path.Contains(".")*/)
{
uri.Path += '/';
}
Expand Down

0 comments on commit 0366765

Please sign in to comment.