public RedirectToCanonicalUrlRule(int statusCode, bool forceLowercaseUrls, TrailingSlashAction trailingSlash)
 {
     StatusCode          = statusCode;
     _forceLowercaseUrls = forceLowercaseUrls;
     _trailingSlash      = trailingSlash;
 }
Ejemplo n.º 2
0
        public async Task CheckStripTrailingSlash(string requestUri, string redirectUri, bool forceLowercaseUrls, TrailingSlashAction trailingSlash)
        {
            var options = new RewriteOptions().AddCanonicalUrl(StatusCodes.Status307TemporaryRedirect, forceLowercaseUrls, trailingSlash);
            using var host = new HostBuilder()
                .ConfigureWebHost(webHostBuilder =>
                {
                    webHostBuilder
                    .UseTestServer()
                    .Configure(app =>
                    {
                        app.UseRewriter(options);
                    });
                }).Build();

            await host.StartAsync();

            var server = host.GetTestServer();

            var response = await server.CreateClient().GetAsync(new Uri(requestUri));

            Assert.Equal(redirectUri, HttpUtility.UrlDecode(response.Headers.Location.OriginalString));
        }
Ejemplo n.º 3
0
        public static RewriteOptions AddCanonicalUrl(this RewriteOptions options, int statuscode, bool forceLowercaseUrls, TrailingSlashAction trailingSlash)
        {
            options.Add(new RedirectToCanonicalUrlRule(statuscode, forceLowercaseUrls, trailingSlash));

            return(options);
        }