views:

278

answers:

3

I have an MVC app that is working fine, but I now want to add in an SSL site to the app.

This is a separate site in IIS, with the SSL certificate, but for re-use, I'm just pointing the SSL site to the same directory as the regular site.

What I'd like to do now, is direct the user to a certain controller (payment) if they come in on the secure url. Otherwise, they can continue on as they were.

What is the best way to do this?

Routing? Filters? Custom BaseController?

How can I ensure that no matter what route they try, if their Request.Url.Host is my secure url, then they'll get redirected. In the future if I add new controllers and actions, I don't want to have to put this in every controller.

Is there a way, application wide, that I can tell all controllers to redirect if a certain url is found?

A: 

If you don't want to use MVC Futures, I can vouch for the simplicity and effectiveness of this solution: http://weblogs.asp.net/cibrax/archive/2009/01/19/running-a-partial-ssl-website-in-asp-net-mvc.aspx

gWiz
+1  A: 

Decorate your method with:

[RequireSsl(Redirect = true)]
Brian David Berman
A: 

[RequireHttps] is now part of ASP.NET MVC 2

Simon_Weaver