ProfileService.aspx
<%@ Register Assembly="Microsoft.Web.Preview" Namespace="Microsoft.Web.Preview.UI.Controls"
TagPrefix="asp" %><!--要把Microsoft.Web.Preview.dll引用到bin目录下-->
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:ProfileService ID="ProfileService1" runat="server" AutoSave="true">
</asp:ProfileService>
<asp:DragOverlayExtender ID="DragOverlayExtender1" runat="server" Enabled="True" TargetControlID="Calendar1" ProfileServiceID="ProfileService1" ProfileProperty="calendarPosition" />
<asp:DragOverlayExtender ID="DragOverlayExtender2" runat="server" Enabled="true"
TargetControlID="Login1" ProfileProperty="loginPosition" ProfileServiceID="ProfileService1" />
<asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="#3366CC"
BorderWidth="1px" CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana"
Font-Size="8pt" ForeColor="#003399" Height="200px" Width="220px">
<SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<TodayDayStyle BackColor="#99CCCC" ForeColor="White" />
<SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
<WeekendDayStyle BackColor="#CCCCFF" />
<OtherMonthDayStyle ForeColor="#999999" />
<NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" />
<DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" />
<TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px" Font-Bold="True"
Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" />
</asp:Calendar>
<asp:Login ID="Login1" runat="server" BackColor="#EFF3FB" BorderColor="#B5C7DE" BorderPadding="4" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333">
<TitleTextStyle BackColor="#507CD1" Font-Bold="True" Font-Size="0.9em" ForeColor="White" />
<InstructionTextStyle Font-Italic="True" ForeColor="Black" />
<TextBoxStyle Font-Size="0.8em" />
<LoginButtonStyle BackColor="White" BorderColor="#507CD1" BorderStyle="Solid" BorderWidth="1px"
Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284E98" />
</asp:Login>
</div>
</form>
Web.config
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="server=.;database=asp_net;uid=sa;pwd=sa" providerName="System.Data.SqlClient"/>
</connectionStrings><!--启用ProfileService会使用aspnet_Profile表保存位置信息-->
<system.web>
<!--其它配置信息-->
<profile enabled="true">
<properties><!--添加属性,分别用来保存日历和登录控件的位置-->
<add name="calendarPosition" allowAnonymous="true" type="String"/>
<add name="loginPosition" allowAnonymous="true" type="String"/>
</properties>
</profile><!--启用对匿名用户保存个性化信息的支持-->
<anonymousIdentification enabled="true"/>
</system.web>
<system.web.extensions>
<scripting>
<webServices>
<!--设置读写属性 -->
<profileService enabled="true" readAccessProperties="calendarPosition,loginPosition" writeAccessProperties="calendarPosition,loginPosition"/>
</webServices>
</scripting>
</system.web.extensions>
运行页面,拖动并刷新页面,Calendar和Login会保留上次的位置,分别在IE和firefox中测试,可以跨浏览器
查看aspnet_profile表会查到以下类似记录:
UserId PropertyNames PropertyValuesString
894E65AD-E188-46F6-87D2-0BBFD0B25332 loginPosition:S:0:5:calendarPosition:S:5:6: 85,21337,96