tallesl / net-TrailingSlash

Redirects the request to the same URL with a trailing slash for a given set of cases.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TrailingSlash

Redirects the request to the same URL with a trailing slash for a given set of cases.

I'm not here to argue "to slash or not slash" (1 2 3), but if you choose to do so, this is what I use for ASP.NET (MVC) web sites.

Usage

using TrailingSlashLibrary;

var slash = new TrailingSlash();

You can configure some set of exceptions (urls to leave alone). There are flags for empty urls (ExceptEmpty), with extension (ExceptWithExtension) and from API (ExceptFromApi). All set to True by default.

You can also add exceptions of your own in the Except property, such as:

slash.Except =
    url =>
    {
        return url.Contains("mini-profiler-resources");
    };

(here we are ignoring MiniProfiler calls)

Now it's just a matter to put an Append call in you Application_BeginRequest:

protected void Application_BeginRequest(object sender, EventArgs e)
{
    slash.Append();
}

Done.

About

Redirects the request to the same URL with a trailing slash for a given set of cases.


Languages

Language:C# 100.0%