今天早上做profile的測試,webconfig的配置如下:
Code
<configuration>
<appSettings/>
<connectionStrings>
<add name="MsSqlConnString" connectionString="server=WSH-S0712002\SQL2005;user id=sa;password=CjchnwsCq53b4y;database=ReplaceShop;min pool size=4;max pool size=4;packet size=3072" providerName="System.Data.SqlClient"></add>
</connectionStrings>
<system.web>
<compilation debug="true"/>
<authentication mode="Forms"/>
<anonymousIdentification enabled="true"/>
<profile enabled="true" automaticSaveEnabled="false" defaultProvider="SupperStudentProvider">
<providers>
<add name="SupperStudentProvider" connectionStringName="MsSqlConnString" type="System.Web.Profile.SqlProfileProvider" applicationName="ReplaceShop 1.0"/>
</providers>
<properties>
<add name="FavoriteColor" allowAnonymous="true" defaultValue="Red" provider="SupperStudentProvider"/>
</properties>
</profile>
</system.web>
</configuration>
Code
//Anonymous.aspx
<%@ Page Language="C#" %>
<script runat="server">
void Login(Object s, EventArgs e)
{
FormsAuthentication.SetAuthCookie("Bill", false);
Response.Redirect(Request.Path);
}
void Logout(Object s, EventArgs e)
{
FormsAuthentication.SignOut();
Response.Redirect(Request.Path);
}
void UpdateProfile(Object s, EventArgs e)
{
Profile.FavoriteColor= txtFavoriteColor.Text;
}
void Page_PreRender()
{
lblUsername.Text = Profile.UserName;
lblFavoriteColor.Text = Profile.FavoriteColor;
}
</script>
<html>
<head>
<title>Anonymous</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button1"
Text="Login"
OnClick="Login"
Runat="Server" />
<asp:Button ID="Button2"
Text="Logout"
OnClick="Logout"
Runat="Server" />
<hr />
<asp:TextBox
id="txtFavoriteColor"
Runat="Server" />
<asp:Button ID="Button3"
Text="Update Profile"
OnClick="UpdateProfile"
Runat="Server" />
<hr />
<b>Username:</b>
<asp:Label
id="lblUsername"
Runat="Server" />
<br />
<b>Favorite Color:</b>
<asp:Label
id="lblFavoriteColor"
Runat="Server" />
</form>
</body>
</html>
發現如下錯誤:
找不到預存程序'dbo.aspnet_CheckSchemaVersion'
解決方案:
導航到目錄C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727,執行aspnet_regsql.exe,一定要選對資料庫(跟webconfig中connectionString中保持一致)