Reputation: 35963
I'm using SSL in my ASP.NET MVC 3 application. Once that the user enters in HTTPS mode, all the links in the page are generated with the HTTPS preface, but I'd like to "let the user leave" the HTTPS mode, and get back to HTTP when critical information exchange has been already done.
Is there anyway in the Routes configuration or something to say something like:
/Home/Index will be always HTTP
I've tried with:
<a href="@Url.Action("Index","Home",null,"http")">Normal</a>
But it fails when I'm using a custom port. I mean, at the beginning it is: http://127.0.0.1:5104/Home/Index
but when the link is generated from HTTPS it looks: http://127.0.0.1/Home/Index
and of course it doesn't work
Regards.
Upvotes: 0
Views: 1228
Reputation: 8885
As the user is browsing an HTTPS page, the request itself doesn't contain any information with respect to what port the HTTP binding is running on. which means that you would need to supply it yourself (it might be possible to get this value out from the IIS config file somehow).
Below is a sample helper function that allows you to specify which http port the request should be routed to.
public static string HttpAction(this UrlHelper helper, string action,
string controller, object routeValues, int port)
{
var url = helper.Action(action, controller, routeValues, "http");
var uri = new Uri(url);
var builder = new UriBuilder(uri.Scheme, uri.Host, port, uri.AbsolutePath, uri.Query);
return builder.ToString();
}
Usage:
@Url.HttpAction("index", "account", new { val = 5 }, 5055);
Upvotes: 2