开发者

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? Lik开发者_运维问答e 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?


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()
    {
        // ...
    }
}


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜