Page

How to use profile serialization in asp.net

//ProfileSerialization.aspx


<%@ Page Language="C#" %>  
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  
<script runat="server">  
    protected void Page_Load(object sender, System.EventArgs e)  
    {   
        if(!this.IsPostBack)  
        {  
            Profile.Name = "KakPakhi";  
            Profile.City = "Rome";  
            Profile.JoinDate = DateTime.Now;  
            Profile.Save();  
        }  
    }  
    protected void Button1_Click(object sender, System.EventArgs e) {  
        Label1.Text = "Profile data read...<br /><br />";  
        Label1.Text += "<i>Name: " + Profile.Name;  
        Label1.Text += "<br />City: " + Profile.City;  
        Label1.Text += "<br />Join Date: " + Profile.JoinDate.ToLongDateString() + "</i>";  
    }  
</script>  
  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>How to use profile serialization in asp.net (serializeAs String,Xml,Binary)</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h2 style="color:Navy">asp.net Profile example: Profile Serialization</h2>  
        <asp:Label   
             ID="Label1"   
             runat="server"   
             Font-Size="Large"   
             Font-Bold="true"  
             ForeColor="SeaGreen"  
             >  
        </asp:Label>  
        <br /><br />  
        <asp:Button   
             ID="Button1"   
             runat="server"   
             Font-Bold="true"   
             ForeColor="SteelBlue"  
             Text="Show Profile"  
             OnClick="Button1_Click"  
             />  
    </div>  
    </form>  
</body>  
</html>  





//web.config [Modified Parts]


<authentication mode="Windows" />  
<profile>  
  <properties>  
    <add name="Name" type="System.String" serializeAs="String"/>  
    <add name="City" type="System.String" serializeAs="Xml"/>  
    <add name="JoinDate" type="System.DateTime" serializeAs="Binary"/>  
  </properties>  
</profile>  

No comments:

Post a Comment