Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request.Url.GetLeftPart(UriPartial.Authority) returns http on https site

We use Request.Url.GetLeftPart(UriPartial.Authority) to get the domain part of the site. This served our requirement on http. We recently change site to https (about 3 days ago) but this still returns with http://.. Urls were all changed to https and show in browser address bar.

Any idea why this happens?

like image 864
kapz Avatar asked Jun 03 '14 06:06

kapz


3 Answers

The following example works fine and returns a string with "https":

var uri = new Uri("https://www.google.com/?q=102njgn24gk24ng2k");
var authority = uri.GetLeftPart(UriPartial.Authority);
// authority => "https://www.google.com"

You either have an issue with the HttpContext class right here, or all your requests are still using http:

  1. You can check the requests HttpContext.Current.Request.IsSecureConnection property. If it is true, and the GetLeftPart method still returns http for you, I think you won't get around a replacing here.
  2. If all your requests are really coming with http, you might enforce a secure connection in IIS.

You should also inspect the incoming URL and log it somewhere for debugging purposes.

like image 165
Herdo Avatar answered Nov 09 '22 23:11

Herdo


This can also happen when dealing with a load balancer. In one situation I worked on, any https requests were converted into http by the load balancer. It still says https in the browser address bar, but internally it's a http request, so the server-side call you are making to GetLeftPart() returns http.

like image 6
Greg Avatar answered Nov 09 '22 23:11

Greg


If your request is coming from ARR with SSL Offloading, Request.Url.GetLeftPart(UriPartial.Authority) just get http

like image 2
heavenwing Avatar answered Nov 10 '22 00:11

heavenwing