简体   繁体   English

ASP.Net - ProfileCommon Save() 不工作!

[英]ASP.Net - ProfileCommon Save() not working!

I have been banging my head over saving the Profile the whole day but couldn't accomplish it.我整天都在努力保存个人资料,但无法完成。
I am able to create a profile, delete, but not edit the details!我可以创建个人资料,删除,但不能编辑详细信息!

After hustling with it for a while, after looking at the SQL Server Profiler logs, I understood I was indeed saving the details but somehow the same sproc is updating the record with previous details!在忙碌了一段时间之后,在查看了 SQL Server Profiler 日志之后,我知道我确实在保存详细信息,但不知何故,同一个 sproc 正在用以前的详细信息更新记录! Tried debugging but neither the page or master page's pageload event was hit!尝试调试,但页面或母版页的 pageload 事件均未命中!

Could it be a problem with db transaction?数据库事务可能有问题吗? But my code has no transaction handling functionality, so I doubt if it has to do anything with rollback or stuff like that!但是我的代码没有事务处理功能,所以我怀疑它是否必须对回滚或类似的东西做任何事情!

Here's my code, just in case if someone could find the bug !这是我的代码,以防万一有人能找到错误

web.config web.config

<profile defaultProvider="CustSqlProfileProvider" enabled="true">
            <providers>
                <add name="CustSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="connString" applicationName="/save_online"/>
            </providers>
            <properties>
                <add name="FirstName" type="System.String"/>
                <add name="LastName" type="System.String"/>
                <add name="Email" type="System.String"/>
                <group name="Address">
                    <add name="Street" type="System.String"/>
                    <add name="City" type="System.String"/>
                    <add name="PostalCode" type="System.String"/>
                </group>
                <group name="Contact">
                    <add name="Phone" type="System.String"/>
                    <add name="Mobile" type="System.String"/>
                </group>
                <add name="ShoppingCart" type="psb.website.BLL.Store.ShoppingCart" serializeAs="Binary" allowAnonymous="true"/>
            </properties>
        </profile>

code代码

private void UpdateProfile()
    {
        ProfileCommon myprofile = this.Profile.GetProfile(HttpContext.Current.User.Identity.Name);
        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();
        myprofile.Save();
    }

In SQL Profiler trace在 SQL Profiler 跟踪

exec dbo.aspnet_Profile_SetProperties is executed with right values when ProfileCommon's save() is called and after the page is done loading, the same st.procedure is executed again with previous values. exec dbo.aspnet_Profile_SetProperties在调用 ProfileCommon 的 save() 时使用正确的值执行,并且在页面完成加载后,使用以前的值再次执行相同的 st.procedure。 How is it called second time?!怎么叫第二次?! This is so annoying!!这太烦人了!!

Would this data from SQL Server Profiler help?这些来自 SQL Server Profiler 的数据会有帮助吗?

 -- network protocol: LPC
    set quoted_identifier on
    set arithabort off
    set numeric_roundabort off
    set ansi_warnings on
    set ansi_padding on
    set ansi_nulls on
    set concat_null_yields_null on
    set cursor_close_on_commit off
    set implicit_transactions off
    set language us_english
    set dateformat mdy
    set datefirst 7
    set transaction isolation level read committed

More info: Admin is able to update profile information of other users but not able update his own profile.更多信息:管理员能够更新其他用户的个人资料信息,但不能更新他自己的个人资料。 And other web site users are also unable to update their profile info!和其他 web 网站用户也无法更新他们的个人资料信息!

How strange!多么奇怪!

Someone please bail me out!有人请保释我!

This seems to be a duplicate of your other profile save question .这似乎与您的其他个人资料保存问题重复。 Regardless, you do not need to call Save at the end.无论如何,您不需要在最后调用 Save。 This automatically happens if you have the auto save feature turned on in the config.如果您在配置中打开了自动保存功能,这会自动发生。 If you want to explicitly call Save, just turn that setting off and things should work like you expect.如果您想显式调用 Save,只需关闭该设置,事情就会如您所愿。

Similar to this question.类似于这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM