ASP.NET Profile save overwritten by old values

谁说胖子不能爱 提交于 2019-12-04 04:59:47

The profile is by default automatically saved at the end of the execution of an ASP.NET page, see the profile Element (ASP.NET Settings Schema) documentation on this. This explains the second "mysterious" save that you observe.

You can try to change automaticSaveEnabled to false.

all the transactions must be done before page unload. if page is unloaded then its all function calls will also be removed or stopped in midway.

Access to ProfileCommon should be done through HttpContext.Current.Profile as that is a reference to the current user's profile (logged in or anonymous) and you don't need to explicitly call Save. Try this:

private void UpdateProfile()
{
    var myprofile = HttpContext.Current.Profile as ProfileCommon;

    if (profile == null) {
        throw new InvalidOperationException("HttpContext.Current.Profile is not of type ProfileCommon for some reason!");
    }

    myprofile.FirstName = tbFirstName.Text.Trim();
    myprofile.LastName = tbLastName.Text.Trim();
    myprofile.Email = tbEmail.Text.Trim();
    myprofile.Address.Street = tbStreetPhysical.Text.Trim();
    myprofile.Address.City = tbCity.Text.Trim();
    myprofile.Address.PostalCode = tbPostalCode.Text.Trim();
    myprofile.Contact.Phone = tbPhone1.Text.Trim();
    myprofile.Contact.Mobile = tbMobile.Text.Trim();
}
ibram

You may need to clear the default provider in your web.config. Like this:

<profile defaultProvider="CustSqlProfileProvider" enabled="true">
    <providers>
        <clear /><!-- here -->
        <add name="CustSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="connString" applicationName="/space_online"/>
    </providers>
    <properties>
        <...>
    </properties>
</profile>

Here is a good explanation for this: Removing existing profile providers

And here is another good site: http://odetocode.com/articles/440.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!