Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC - How to Redirect Secure?

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?

like image 651
Scott Klarenbach Avatar asked Nov 06 '22 19:11

Scott Klarenbach


1 Answers

Decorate your method with:

[RequireSsl(Redirect = true)]
like image 180
Brian David Berman Avatar answered Nov 11 '22 14:11

Brian David Berman