I am working on a local server and I need a specific URL to be accessed through HTTPS while the rest through HTTP. I have configured Visual Studio to use IIS Express so I can use HTTP/SSL.
I have a method like so:
[RequireHttps]
public ActionResult SomeHttpsMethod()
{
//Do something
}
In another place I have:
var url = Url.Action("SomeHttpsMethod", "SomeHttpsController", new { someParams }, Request.Url.Scheme);
If I access my site using HTTP
i.e. http://localhost:httpport
, I still get HTTP
returned from Request.Url.Scheme
instead of HTTPS
. Is that how it is meant to work?
Obviously if I accesss my site using HTTPS
i.e. to begin with i.e. https://localhost:sslport
, HTTPS
is returned (which is what I want) but I don't want to have to access the site in HTTPS
, only for that particular URL/controller method.
This line:
var url = Url.Action("SomeHttpsMethod", "SomeHttpsController",
new { someParams }, Request.Url.Scheme);
constructs a URL based on your current request's scheme, which is HTTP. Request
always refers to the current request.
You'd be better off hard-coding "https" in this place since you always want it to be secure anyway:
var url = Url.Action("SomeHttpsMethod", "SomeHttpsController",
new { someParams }, "https");
In my case it was down to badly set up rules on the ARR server. Just something to look at if you get HTTP rather than HTTPS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With