2009-08-31 172 views

回答

71

您可以参考HttpRequest类中的Request.IsSecureConnection属性。要在页面之外的全部参考,用户控制或类似情况下使用HttpContext.Current.Request.IsSecureConnection

+7

要小心 - IsSecureConnection可能会给出错误的否定结论。 http://stackoverflow.com/questions/998397/why-does-request-issecureconnection-return-false-when-true-is-expected – 2011-03-28 21:13:39

+1

答案是有点老,所以现在,对我来说,它与owin有点改变。我通过“System.Web.HttpContext.Current.GetOwinContext()。Request.IsSecure”获得了该值。这可能会在稍后发生。 :) – MGR 2016-05-11 11:11:44

5

使用 - HttpContext.Current.Request.IsSecureConnection

3

或者:

Request.ServerVariables["SERVER_PROTOCOL"]; 
+1

这会在http和https上为我返回'HTTP/1.1',而Request.IsSecureConnection'按预期返回。 – atheaos 2016-01-27 15:27:53

0

试试这个,

aCookie.Secure = HttpContext.Current.Request.IsSecureConnection 
0

更新ASPNET核2.0,现在,你应该用你的Request.IsHttps控制器内部。

相关问题