chobo2
chobo2

Reputation: 85855

How to make pages automatically use https when using asp.net mvc 2.0

I am wondering how do I make pages automatically use https? Like if a user types in

http://www.mysite.com

It should take them right to the login page. However I have SSL required on this page(when they try to login).

So how could I make it so it would change it to

https://www.mysite.com even if they don't type it in themselfs?

Upvotes: 4

Views: 1323

Answers (2)

Samuel
Samuel

Reputation: 9993

i believe you are looking for

 [RequireSsl(Redirect = true)] 

there is a discussion you can find here

SSL pages under ASP.NET MVC

Edited: found this link might be useful

http://blog.stevensanderson.com/2008/08/05/adding-httpsssl-support-to-aspnet-mvc-routing/

Upvotes: 1

LukeH
LukeH

Reputation: 269618

You can use the RequireHttpsAttribute on the appropriate controllers and/or actions:

[RequireHttps]
public class SecureController : Controller
{
    public ActionResult YourAction()
    {
        // ...
    }
}

// ...

public class YourController : Controller
{
    [RequireHttps]
    public ActionResult SecureAction()
    {
        // ...
    }
}

Upvotes: 3

Related Questions