HttpCookie.Secure HttpCookie.Secure HttpCookie.Secure HttpCookie.Secure Property

定义

获取或设置一个值,该值指示是否使用安全套接字层 (SSL)(即仅通过 HTTPS)传输 Cookie。Gets or sets a value indicating whether to transmit the cookie using Secure Sockets Layer (SSL)--that is, over HTTPS only.

public:
 property bool Secure { bool get(); void set(bool value); };
public bool Secure { get; set; }
member this.Secure : bool with get, set
Public Property Secure As Boolean

属性值

如果通过 SSL 连接 (HTTPS) 传输 Cookie,则为 true;否则为 falsetrue to transmit the cookie over an SSL connection (HTTPS); otherwise, false. 默认值为 falseThe default value is false.

示例

如果 cookie 设置为使用 SSL 传输,则下面的代码示例将采取措施。The following code example takes action if the cookie is set to transmit using SSL.

if (MyCookie.Secure)
 {
   //...
 }
    
If MyCookie.Secure Then
    '...
 End If
    

注解

若要使用 SSL 为整个应用程序设置 cookie 传输,请在应用程序的配置文件(位于应用程序的根目录下)中启用它。To set the transmission of cookies using SSL for an entire application, enable it in the application's configuration file, Web.config, which resides in the root directory of the application. 有关详细信息,请参阅HttpCookies 元素(ASP.NET Settings Schema)For more information, see httpCookies Element (ASP.NET Settings Schema). 使用在 web.config 文件中Secure设置的属性重写值以编程方式设置的值。Values set programmatically using the Secure property override values set in the Web.config file.

处理敏感信息时,强烈建议你将 HTTPS 协议与 SSL 加密配合使用。When dealing with sensitive information, it is strongly recommended that you use HTTPS protocol with SSL encryption. SSL 可防止更改数据(数据完整性)、保护用户的标识(机密性),并确保数据来自预期客户端(身份验证)。SSL protects against data being altered (data integrity), protects a user's identity (confidentiality), and assures that data originates from the expected client (authentication). 有关加密的优势的详细信息,请参阅加密服务For more information on the benefits of encryption, see Cryptographic Services. 有关在 Internet Information Services (IIS) Web 服务器上配置 SSL 的详细信息,请参阅在 Web 服务器或网站上配置 sslFor more information about configuring SSL on an Internet Information Services (IIS) Web server, see Configuring SSL on a Web Server or a Web Site.

适用于

另请参阅