Melody
Melody

Reputation: 1203

Find URL scheme

I want to check whether the incoming url having http or https in c#? Is there any default method to find the url scheme(http/https)?

Upvotes: 2

Views: 5886

Answers (2)

John Sobolewski
John Sobolewski

Reputation: 4572

You could use Uri.Scheme to check and see if it is https.

You could also just use Request.IsSecureConnection

Upvotes: 5

Kinexus
Kinexus

Reputation: 12904

var currentUrl = System.Web.HttpContext.Current.Request.Url;
if (!currentUrl.Scheme.Equals(Uri.UriSchemeHttps, 
    StringComparison.CurrentCultureIgnoreCase))

For more information : Uri.UriSchemeHttps Field

Upvotes: 2

Related Questions