c# https mvc

ITsolutionWizard used Ask the Experts™
i use @HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) but it does not read https. it read http only. how to fix it?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®


no one here to help out?
So if I understand you correctly, you have a site in ASP.NET / C#, and you're accessing it securely, like https://www.yourdomain.com/something.aspx and you want HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) to return "https://www.yourdomain.com" but it's returning "http://www.yourdomain.com".

The first thing to do is double-check the IsSecureConnection property:

If that says false, but your browser shows https:// in the address bar, then probably what's happening is that you've got SSL terminated at some other intermediate server, like an f5. It's pretty common with load balancers or security appliances.

In other words, the browser is not talking directly to your web server - it is talking to another server that sits IN FRONT OF your web server. Then that other server is handling all the SSL, and is relaying the unencrypted request back to your web server. So your code always and only sees HTTP, not HTTPS requests (which can be okay if it's all within your own network):

[ Your Web Server ] <--- HTTP ---> [ Load Balancer ] <--- HTTPS ---> [ Browser ]
\_________________________________________________/ \_______________/
                  YOUR NETWORK                       PUBLIC INTERNET

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial