Specifies whether view-state information is encrypted.
Namespace:
System.Web.UI
Assembly:
System.Web (in System.Web.dll)
Visual Basic (Declaration)
Public Enumeration ViewStateEncryptionMode
Dim instance As ViewStateEncryptionMode
public enum ViewStateEncryptionMode
public enum class ViewStateEncryptionMode
public enum ViewStateEncryptionMode
| Member name | Description |
|---|
| Auto | The view-state information is encrypted if a control requests encryption by calling the RegisterRequiresViewStateEncryption method. This is the default. |
| Always | The view-state information is always encrypted. |
| Never | The view-state information is never encrypted, even if a control requests it. |
The ViewStateEncryptionMode enumeration provides values for specifying whether the view-state information in a Page object is encrypted. The ViewStateEncryptionMode value can be set only in the @ Page directive or in the pages section of the configuration file.
The following code example demonstrates setting the view-state encryption mode for a Page object and requesting encryption of the view-state information through the RegisterRequiresViewStateEncryption method. In this example, the view-state information will be encrypted when customer information is retrieved from a database.
<%@ Page Language="VB" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If IsPostBack Then
If (yesRetrieve.Checked) Then
Page.RegisterRequiresViewStateEncryption()
Dim conn As System.Data.SqlClient.SqlConnection = _
New System.Data.SqlClient.SqlConnection _
("server=localhost;database=Northwind;Integrated Security=SSPI")
Dim command As System.Data.SqlClient.SqlCommand = _
conn.CreateCommand()
command.CommandText = "Select [CustomerID] From [Customers]"
conn.Open()
Dim reader As System.Data.SqlClient.SqlDataReader = _
command.ExecuteReader()
customerid.Text = reader("CustomerID").ToString()
reader.Close()
conn.Close()
End If
End If
End Sub
</script>
<html >
<head id="Head1" runat="server">
<title>Customer Information</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Customer identifier:
<asp:Label ID="customerid" runat="server" Text="Not available" />
<br />
Retrieve customer info:
<asp:RadioButton ID="yesRetrieve" Text="yes" runat="server" GroupName="group1" />
<asp:RadioButton ID="noRetrieve" Text="no" runat="server" GroupName="group1" />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
if (IsPostBack)
{
if (yesRetrieve.Checked)
{
Page.RegisterRequiresViewStateEncryption();
System.Data.SqlClient.SqlConnection conn =
new System.Data.SqlClient.SqlConnection
("server=localhost;database=Northwind;Integrated Security=SSPI");
System.Data.SqlClient.SqlCommand command =
conn.CreateCommand();
command.CommandText = "Select [CustomerID] From [Customers]";
conn.Open();
System.Data.SqlClient.SqlDataReader reader =
command.ExecuteReader();
customerid.Text = reader["CustomerID"].ToString();
reader.Close();
conn.Close();
}
else
{
customerid.Text = "Not retrieved";
}
}
}
</script>
<html >
<head id="Head1" runat="server">
<title>Customer Information</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Customer identifier:
<asp:Label ID="customerid" runat="server" Text="Not available" />
<br />
Retrieve customer info:
<asp:RadioButton ID="yesRetrieve" Text="yes" runat="server" GroupName="group1" />
<asp:RadioButton ID="noRetrieve" Text="no" runat="server" GroupName="group1" />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
</div>
</form>
</body>
</html>
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0
Reference
Other Resources