Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the protocol when using RedirectToAction?

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)

like image 984
Mathias F Avatar asked Feb 20 '10 11:02

Mathias F


1 Answers

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"));
}
like image 190
Çağdaş Tekin Avatar answered Oct 13 '22 21:10

Çağdaş Tekin