ASP.Net - ProfileCommon Save() 不起作用!

发布于 2024-11-10 03:19:17 字数 2985 浏览 3 评论 0原文

我一整天都在绞尽脑汁地保存个人资料,但未能完成。
我可以创建个人资料、删除个人资料,但不能编辑详细信息!

经过一段时间的忙碌后,在查看了 SQL Server Profiler 日志后,我明白我确实在保存详细信息,但不知何故,同一个存储过程正在用以前的详细信息更新记录!尝试调试,但页面或母版页的页面加载事件都没有被命中!

难道是db事务的问题?但我的代码没有事务处理功能,所以我怀疑它是否必须执行回滚或类似的操作!

这是我的代码,以防万一有人发现错误

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>

代码

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();
    }

在 SQL Profiler 跟踪中,

当调用 ProfileCommon 的 save() 且页面打开后,exec dbo.aspnet_Profile_SetProperties 将使用正确的值执行加载完成后,将使用之前的值再次执行相同的 st.procedure。 怎么叫第二次?!这太烦人了!!

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

更多信息: 管理员可以更新其他用户的个人资料信息,但无法更新自己的个人资料。其他网站用户也无法更新他们的个人资料信息!

多么奇怪啊!

请有人保释我!

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! Tried debugging but neither the page or master page's pageload event was hit!

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

<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

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.
How is it called second time?! This is so annoying!!

Would this data from SQL Server Profiler help?

 -- 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!

How strange!

Someone please bail me out!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长亭外,古道边 2024-11-17 03:19:17

这似乎与您的其他个人资料保存问题重复。无论如何,您不需要在最后调用 Save。如果您在配置中打开了自动保存功能,则会自动发生这种情况。如果您想显式调用“保存”,只需关闭该设置,事情就会像您期望的那样工作。

This seems to be a duplicate of your other profile save question. Regardless, you do not need to call Save at the end. 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.

_畞蕅 2024-11-17 03:19:17

类似于这个问题。

Similar to this question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文