Detecting https from HttpContext in .net?

前端 未结 3 926
天涯浪人
天涯浪人 2021-01-01 11:37

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

相关标签:
3条回答
  • 2021-01-01 11:51

    You can use HttpContext.Current.Request.IsSecureConnection

    0 讨论(0)
  • 2021-01-01 11:53

    I use this code to auto redirect to https

    If HttpContext.Current.Request.IsSecureConnection.Equals(False) Then
        Response.Redirect("https://" + Request.ServerVariables("HTTP_HOST") & HttpContext.Current.Request.RawUrl)
    End If
    
    0 讨论(0)
  • 2021-01-01 12:10

    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.

    0 讨论(0)
提交回复
热议问题