0

How can I configure my ASP.NET MVC 3 application to use HTTP on login and HTTPS on the rest of the pages?

Now I configured the app to use HTTPS on every page including Login.

Does anyone have any suggestions?

Thanks a lot.

Jeff

Jeff Norman
  • 1,014
  • 5
  • 25
  • 42

1 Answers1

1

You can use the built-in RequireHttpsAttribute see the documentation reference

You can set this on your controller class like this:

[RequireHttps]
public Controller HomeController() { }

All actions of this controller will use Https.

Or directly on a controller action

[RequireHttps]
public ActionResult Index() { }

You may also register this for the entire app on your global.asax

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
  filters.Add(new HandleErrorAttribute());
  filters.Add(new RequireHttpsAttribute());
}
Dominic St-Pierre
  • 2,429
  • 3
  • 27
  • 35