I've inherited a pile of code for a web app which contains oodles of hard-coded paths. I've been tasked with trying to get it to run using https://.
Other than detecting "https://" in the URL is there a more inband way to detect that the current context is https?
Looking for something like:
System.Web.HttpContext.Current.Request.Url.Protocol.ToString()
HttpContext object is not thread-safe.
This property is a static property of the HttpContext class. The property stores the HttpContext instance that applies to the current request. The properties of this instance are the non-static properties of the HttpContext class. You can also use the Page.
For more information and example code, see ASP.NET Core Blazor Server additional security scenarios. HttpContext encapsulates all information about an individual HTTP request and response. An HttpContext instance is initialized when an HTTP request is received.
You can use HttpContext.Current.Request.IsSecureConnection
The direct answer to your request for something like System.Web.HttpContext.Current.Request.Url.Protocol.ToString()
is System.Web.HttpContext.Current.Request.Url.Scheme
, though as Brandon says, in his answerHttpContext.Current.Request.IsSecureConnection
is the way to detect use of https as a boolean and likely more appropriate to the problem you give in your question.
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