2009-08-31 58 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控制器內部。

相關問題