views:

71

answers:

2

I want to create a action filter that will check the url, and if its not using Ssl, redirect to the same page but with SSL.

What is the best way of doing this?

Should I just check the RawUrl, and scan the string for https, and if its not there then do:

context.Response.Redirect(context.Request.RawUrl.Replace("http:", "https:"));
+1  A: 

There already is one (in MVC 2, at least): RequireSsl. I think it may be in futures in MVC 1, but I haven't used MVC 1 in a long time.

Craig Stuntz
A: 

As a note, it's now the System.Web.Mvc.RequireHttpsAttribute.

I'm on MVC 2.

blesh