RequireHttps Attribute doesn't work in ASP.NET MVC3 on AppHarbor

philiprichardson's Avatar

philiprichardson

11 Apr, 2011 12:04 AM

Repro:
1. Use the RequireHttps attribute on an HttpPost Action
2. Attempt to submit a form to the site over either HTTP or HTTPs
3. Get a "Sorry, an error occurred while processing your request." error in the browser.

Action Code:

    [HttpPost]
    [RequireHttps]
    [ValidateAntiForgeryToken]
    public ActionResult Login(FormCollection collection)
    {
        return RedirectToAction("Index", "Home", null);
    }

Notes:
- My SSL works fine when the RequireHttps attribute is not included - Naturally there are scenarios where all developers will want to restrict HTTP traffic for particular URIs ... so I'd expect it to work.

Phil

  1. Support Staff 1 Posted by rune on 12 Apr, 2011 04:42 PM

    rune's Avatar

    Hi Phillip,

    Https is terminated at the load balancer level on AppHarbor. You can use the "X-Forwarded-Proto" header to determine whether the client used https. I've made a gist so you can see how you can implement your own RequireHttpsAttribute using that header: https://gist.github.com/915869

    Please note that you'll also need to have a certificate associated with the application before it responds to HTTPS traffic.

    Let me know if there's anything else we can help with.

    Best,
    Rune

  2. rune closed this discussion on 12 Apr, 2011 04:42 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac