0

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;

4

1 回答 1

0

通过从 Web.Config 中删除除名字和姓氏属性之外的所有属性来简化它。尝试缩小范围。

以下对我有用。尽管为了方便起见我将anonymousIdentification 设置为true,但我已经为您提供了工作成员Web.Config 条目的完整语法:

<configuration>
  <connectionStrings>
    <remove name="LocalSqlServer"/>
    <add name="LocalSqlServer" 
        connectionString="Initial Catalog=Test;Data Source=MYPCNAME;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
    <anonymousIdentification enabled="true"/>
    <profile>
      <properties>
        <add name="FirstName" type="System.String" allowAnonymous="true"/>
        <add name="LastName" type="System.String" allowAnonymous="true"/>
      </properties>
    </profile>
    <roleManager enabled="true"/>
    <authentication mode="Forms">
      <forms timeout="50000000"/>
    </authentication>
    <membership defaultProvider="SqlProvider">
      <providers>
        <clear/>
        <add name="SqlProvider" 
            type="System.Web.Security.SqlMembershipProvider"
            connectionStringName="LocalSqlServer" 
            enablePasswordReset="true" 
            requiresQuestionAndAnswer="false" 
            requiresUniqueEmail="false" 
            maxInvalidPasswordAttempts="5" 
            passwordAttemptWindow="10" 
            passwordFormat="Hashed" 
            minRequiredPasswordLength="7" 
            minRequiredNonAlphanumericCharacters="0" 
            passwordStrengthReqularExpression="0" 
            enablePasswordRetrieval="false" 
            applicationName="/"/>
      </providers>
    </membership>
    <compilation debug="true" targetFramework="4.0"/>
  </system.web>
</configuration>

    protected void Button1_Click(object sender, EventArgs e)
    {
        ProfileCommon p = (ProfileCommon)ProfileCommon.Create(fnTxt.Text 
            + lnTxt.Text, true);
        Profile.FirstName = fnTxt.Text;
        Profile.LastName = lnTxt.Text;

        p.Save();
    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        resultLabel.Text = Profile.FirstName + " " + Profile.LastName;
    }
于 2012-10-22T02:35:07.027 回答