Asp.net 配置文件不显示或不保存用户输入的数据,但是没有错误。这是下面代码的视图:webproject 刚刚运行,名字和姓氏标签上都没有显示任何内容。
这是一个 WEB 项目 ,,, 我使用 OPEN WEBSITE 打开了这个项目!
但是该项目在 VISUAL STUDIOS 的程序标题栏中显示为“WEBPROJECT.sln(3)”。
这是用户创建帐户并保存用户配置文件设置的时间:新和更新
protected void CreateUserWizard_CreatedUser(object sender, EventArgs e)
{
// Create an empty Profile for the newly created user
ProfileCommon p = (ProfileCommon)ProfileCommon.Create(RegisterUser.UserName, true);
// Save profile - must be done since we explicitly created it
TextBox txtNewFirstName = (TextBox)RegisterUser.FindControl("txtNewFirstName");
Profile.FirstName = txtNewFirstName.Text;
TextBox txtNewLastName = (TextBox)RegisterUser.FindControl("txtNewLastName");
Profile.LastName = txtNewLastName.Text;
p.Save();
}
这就是它的显示时间:NEW AND UPDATED
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
ProfileCommon p = this.Profile.GetProfile(this.User.Identity.Name);
Label firstName = (Label)LoginView1.FindControl("firstName");
Profile.FirstName = firstName.Text;
Label lastName = (Label)LoginView1.FindControl("lastName");
Profile.LastName = lastName.Text;
}
}
这是网络配置:新的和更新的
<profile defaultProvider="AspNetSqlProfileProvider" enabled="true">
<properties>
<add name="FirstName" type="String" serializeAs="String"/>
<add name="LastName" type="String" serializeAs="String"/>
<add name="Gender" type="String" serializeAs="String"/>
<add name="BirthDate" type="DateTime" serializeAs="String"/>
<add name="Occupation" type="String" serializeAs="String"/>
<add name="Website" type="String" serializeAs="String"/>
<group name="Forum">
<add name="Posts" type="Int32" defaultValue="0"/>
<add name="AvatarUrl" type="String" serializeAs="String"/>
<add name="Signature" type="String" serializeAs="String"/>
</group>
<group name="Address">
<add name="Street" type="String" serializeAs="String"/>
<add name="PostalCode" type="String" serializeAs="String"/>
<add name="City" type="String" serializeAs="String"/>
<add name="State" type="String" serializeAs="String"/>
<add name="Country" type="String" serializeAs="String"/>
</group>
<group name="Contacts">
<add name="Phone" type="String" serializeAs="String"/>
<add name="Fax" type="String" serializeAs="String"/>
</group>
</properties>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
这是我的 sql 服务器上的 aspnet_Profile 上显示的内容:
[PropertyNames]
[LastName:S:0:0:FirstName:S:0:0:]
这是对之前代码的重做,所以请忽略下面之前的评论!
我也尝试过PreRender 方法:
<script runat="server">
protected void Page_PreRender(object sender, EventArgs e)
{
ProfileCommon p = this.Profile.GetProfile(this.User.Identity.Name);
Label firstName = (Label)LoginView1.FindControl("firstName");
Profile.FirstName = firstName.Text;
Label lastName = (Label)LoginView1.FindControl("lastName");
Profile.LastName = lastName.Text;
}
但我得到一个错误: 对象引用未设置为对象的实例。对于Profile.FirstName = firstName.Text;