Skip to content
This repository has been archived by the owner on Dec 20, 2018. It is now read-only.

Force HTTPS Middleware #10

Closed
robfarmergt opened this issue Aug 21, 2015 · 2 comments
Closed

Force HTTPS Middleware #10

robfarmergt opened this issue Aug 21, 2015 · 2 comments
Labels

Comments

@robfarmergt
Copy link

Is there a good way to force HTTPS?

@Tratcher
Copy link
Member

A) Only listen on HTTPS when you set up the server.
B) Redirect HTTP to HTTPS:

            app.Use((ctx, next) =>
            {
                if (!string.Equals("https", ctx.Request.Scheme, StringComparison.OrdinalIgnoreCase))
                {
                    ctx.Response.Redirect(UriHelper.Encode("https", ctx.Request.Host, ctx.Request.PathBase, ctx.Request.Path, ctx.Request.QueryString));
                    return Task.FromResult(0);
                }
                return next();
            });

@robfarmergt
Copy link
Author

Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants