Example #1
0
        /// <summary>
        /// Redirects all requests not matching the specified <paramref name="domain"/> to the domain, optionally redirecting HTTP to HTTPS.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="domain">The domain to redirect to if the request is not for the domain specified.</param>
        /// <param name="requireHttps">Redirect any request made over HTTP to HTTPS.</param>
        /// <returns></returns>
        public static IApplicationBuilder UseCanonicalDomain(this IApplicationBuilder builder, string domain = null, bool requireHttps = false)
        {
            var options = new CanonicalDomainOptions
            {
                Domain       = domain,
                RequireHttps = requireHttps
            };

            return(builder.UseMiddleware <CanonicalDomainMiddleware>(Options.Create(options)));
        }
Example #2
0
 /// <summary>
 /// Redirects all requests when not matching the domain in the specified <paramref name="options"/>, optionally redirecting HTTP to HTTPS.
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="options">The options for the canonical domain.</param>
 /// <returns></returns>
 public static IApplicationBuilder UseCanonicalDomain(this IApplicationBuilder builder, CanonicalDomainOptions options)
 {
     return(builder.UseMiddleware <CanonicalDomainMiddleware>(Options.Create(options)));
 }
 /// <summary>
 /// Initialises a new <see cref="CanonicalDomainMiddleware"/> instance.
 /// </summary>
 /// <param name="next">The next middleware in the pipeline.</param>
 /// <param name="options">The configuration for this middleware.</param>
 public CanonicalDomainMiddleware(RequestDelegate next, IOptions <CanonicalDomainOptions> options)
 {
     _next    = next;
     _options = options.Value;
 }