ASP.net检查页面是http还是https

Dra*_*cir 37 asp.net https

我有一个托管在多个服务器上的Web应用程序,其中一些服务器位于https上.如果页面当前是http或https,如何从代码后面检查?

Tro*_*sen 77

你可以参考班上的Request.IsSecureConnection财产HttpRequest.要获得页面外的完整参考,用户控制或类似,请使用HttpContext.Current.Request.IsSecureConnection.

  • 当心 - IsSecureConnection可以给出假阴性.http://stackoverflow.com/questions/998397/why-does-request-issecureconnection-return-false-when-true-is-expected (8认同)
  • 答案有点旧,所以现在,对我来说,有点因为owin而改变了.我通过"System.Web.HttpContext.Current.GetOwinContext().Request.IsSecure"得到了值.对于某些人来说,这可能会派上用场.:) (2认同)

Ras*_*ack 6

使用 - HttpContext.Current.Request.IsSecureConnection


Jul*_*her 5

更新 Aspnet Core 2.0,现在,您应该Request.IsHttps在控制器内部使用。