views:

249

answers:

2

The action I target needs https. I already have a filter in place that redirects to https if a request comes in via http, but I would prefer to send the request via https right from the start.

EDIT

There was an answer from Darin (updated now to something else ) where he asked why I call this first action by http anyway. He had a good point there and I just updated a couple of links. This was the easiest and securest way to fix my problem.

Once I find the time to evaluate çağdaş answer I will use this as the correct answer, because I guess thats of interest for some other people (...including me in the future)

A: 

You may take a look at this article which illustrates how to enable HTTPS at the routing level.

Darin Dimitrov
+3  A: 

I don't know if you must use RedirectToAction but with a UrlHelper and the controller's Redirect method you can do this :

public ActionResult SomeAction() {
    UrlHelper u = new UrlHelper(this.ControllerContext.RequestContext);
    return Redirect(u.Action("actionName", "controllerName", null, "https"));
}
çağdaş
To be honest I dont know the difference between Redirect and RedirectToAction. Maybe there is a difference when TempData is used. I have to to try this one. Looks perfect so far.
Malcolm Frexner
@Malcolm Frexner Well, the difference is that one of them (`Redirect`) takes URI as parameter, whereas the other one takes "some values dictionary" (quoting the source code). And also, there shouldn't be any problems with the TempData, since they both redirect the same way in the end.
çağdaş