Hi there, yesterday I tried the example in Listing 14-10 and it showed the GUID for .ASPXANONYMOUS cookie in fiddler. Yesterday it also showed the profile information that was stored in the database in the response webpage.
But today when I executed the same program, its showing message "You must be authenticated!" which must be because Page.User.Identity.IsAuthenticated returned true as can be seen from the code. Also the header now doesnt show the cookie.
When I remove anonymousIdentification property from the web.config and set authentication mode to Windows in web.config then it responds correctly.
I also tried it on my desktop, no difference.
Please help. Now I am unable proceed for remaining chapter.
Also tell me what sets property Page.User.Identity.IsAuthenticated.
One more question: Where these information is stored by default? Can we see it through SQL Server Management Studio?
I yesterday changed the default database to one empty database I created through aspnet_regsql.exe. I was able to see the stored information in Management Studio. But I was unable to see the same with default settings.
Personalization.aspx
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Personalization.aspx.cs"
Inherits="Personalization" %>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.User.Identity.IsAuthenticated)
{
string oldFirstName,oldLastName,oldAge,oldMember,oldLastVisited;
oldFirstName = Profile.GetPropertyValue("FirstName").ToString();
oldLastName = Profile.GetPropertyValue("LastName").ToString();
oldAge = Profile.GetPropertyValue("Age").ToString();
oldMember = Profile.GetPropertyValue("Member").ToString();
oldLastVisited = Profile.GetPropertyValue("LastVisited").ToString();
Profile.FirstName = TextBox1.Text;
Profile.LastName = TextBox2.Text;
Profile.Age = TextBox3.Text;
Profile.Member = Radiobuttonlist1.SelectedItem.Text;
Profile.LastVisited = DateTime.Now.ToString();
Label1.Text = "Stored information includes:<p>" +
"First name: " + Profile.FirstName +
"<br>Last name: " + Profile.LastName +
"<br>Age: " + Profile.Age +
"<br>Member: " + Profile.Member +
"<br>Last visited: " + Profile.LastVisited+
"<br/><br/> <b> Latebound</b> Old Personalization Information"+
"<br/>First name: "+oldFirstName+
"<br/>Last Name: "+oldLastName+
"<br/>Age: "+oldAge+
"<br/>Member: "+oldMember+
"<br/>Last visited: "+oldLastVisited;
}
else
{
Label1.Text = "You must be authenticated!";
}
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Storing Personalization</title>
</head>
<body>
<form id="form1" runat="server">
<p>
First Name:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></p>
<p>
Last Name:
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></p>
<p>
Age:
<asp:TextBox ID="TextBox3" runat="server" Width="50px" MaxLength="3"></asp:TextBox></p>
<p>
Are you a member?
<asp:RadioButtonList ID="Radiobuttonlist1" runat="server">
<asp:ListItem Value="1">Yes</asp:ListItem>
<asp:ListItem Value="0" Selected="True">No</asp:ListItem>
</asp:RadioButtonList>
</p>
<p>
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
</p>
<hr />
<p>
<asp:Label ID="Label1" runat="server"></asp:Label></p>
</form>
</body>
</html>
web.config
Code:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<profile>
<properties>
<add name="FirstName"/>
<add name="LastName"/>
<add name="LastVisited"/>
<add name="Age"/>
<add name="Member"/>
<add name="Cart" type="ShoppingCart" serializeAs="Binary"/>
</properties>
</profile>
<authentication mode="Windows" />
<anonymousIdentification enabled="true" />
</system.web>
<!--
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=localhost;Initial Catalog=AspNetServicesDB;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings> -->
</configuration>