ASP.NET配置文件保存由旧的值覆盖 [英] ASP.NET Profile save overwritten by old values

查看:155
本文介绍了ASP.NET配置文件保存由旧的值覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的一个网站 ASP.NET 的配置文​​件功能。更新配置文件是古怪的工作!用户不能更新他/她自己的空间,无论是网站用户也不管理员,但,管理员是能够更新其他用户的配置文件

在后端,档案的保存()被调用后,SQL Server跟踪显示的 aspnet_Profile_SetProperties 存储过程调用两次。首先,用新值,然后用旧值。第二个执行页卸载后进行。我的code的无关的事务。

为什么工作这么古怪?

莫不是有,因为我已经安装卸载并重新安装了它的 aspnet_regsql 的安装问题!?

code

的web.config

 <身份验证模式=表格>
    <形式的名称=FormsAuthenticationloginUrl =〜/的Login.aspxdefaultUrl =〜/的Login.aspx超时=20/>
< /认证>
<会员defaultProvider =CustSqlMembershipProvider>
    <供应商>
        <添加的connectionStringName =CONNSTRING的applicationName =/ space_onlineminRequiredPasswordLength =5minRequiredNonalphanumericCharacters =0NA​​ME =CustSqlMembershipProviderTYPE =System.Web.Security.SqlMembershipProvider/>
    < /供应商>
< /会员>
< roleManager启用=真正的defaultProvider =CustSqlRoleProvider>
    <供应商>
        <添加的connectionStringName =CONNSTRING的applicationName =/ space_onlineNAME =CustSqlRoleProviderTYPE =System.Web.Security.SqlRoleProvider/>
    < /供应商>
< / roleManager>
< anonymousIdentification无Cookie =自动检测启用=真/>
<型材defaultProvider =CustSqlProfileProvider启用=真>
    <供应商>
        <添加名称=CustSqlProfileProviderTYPE =System.Web.Profile.SqlProfileProvider的connectionStringName =CONNSTRING的applicationName =/ space_online/>
    < /供应商>
    <性状>
        <添加名称=名字TYPE =System.String/>
        <添加名称=姓氏TYPE =System.String/>
        <添加名称=电子邮件TYPE =System.String/>
        <组名=地址>
            <添加名称=街TYPE =System.String/>
            <添加名称=城TYPE =System.String/>
            <添加名称=邮政code型=System.String/>
        < /组>
        <组名=联系>
            <添加名称=手机TYPE =System.String/>
            <添加名称=移动式=System.String/>
            <添加名称=传真TYPE =System.String/>
        < /组>
        <添加名称=我的购物TYPE =psb.website.BLL.Store.ShoppingCartserializeAs =二进制使用AllowAnonymous =真/>
    < /性状>
< / profile文件>

背后code

 私人无效UpdateProfile(的ProfileCommon我的资料)
{
    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.Postal code = tbPostal code.Text.Trim();
    myprofile.Contact.Phone = tbPhone1.Text.Trim();
    myprofile.Contact.Mobile = tbMobile.Text.Trim();
    myprofile.Save();
}
私人的ProfileCommon GetProfile()
    {
        的ProfileCommon轮廓= this.Profile;
        如果(的Request.QueryString [用户名] = NULL&放大器;!&安培; HttpContext.Current.User.IsInRole(管理))
            简介= this.Profile.GetProfile(的Request.QueryString [用户名]的ToString());
        其他
            简介= this.Profile.GetProfile(HttpContext.Current.User.Identity.Name);
        返回的个人资料;
    }
保护无效tbUpdateProfile_Click(对象发件人,ImageClickEventArgs E)
    {
        UpdateProfile(GetProfile());
    }


解决方案

配置文件默认情况下自动保存在一个ASP.NET页面的执行结束,看到的剖面元素(ASP.NET设置架构)本文档。这解释了第二个神秘保存你观察。

您可以尝试改变 automaticSaveEnabled 为假。

I am using the Profile feature of ASP.NET in a website. Updating a profile is working weirdly! A user can't update his/her own profile, neither the web site user nor the administrator, but, the administrator is able to update profiles of other users.

In the backend, after Profile's save() is called, SQL Server traces show that aspnet_Profile_SetProperties stored procedure is called twice. First, with new values, then, with old values. The second execution is done after page unload. My code has nothing to do with transactions.

Why is it working so weirdly?

Could there be an issue with aspnet_regsql's installation as I have installed uninstalled and again installed it!?

Code

web.config

<authentication mode="Forms">
    <forms name="FormsAuthentication" loginUrl="~/Login.aspx" defaultUrl="~/Login.aspx" timeout="20"/>
</authentication>
<membership defaultProvider="CustSqlMembershipProvider">
    <providers>
        <add connectionStringName="connString" applicationName="/space_online" minRequiredPasswordLength="5" minRequiredNonalphanumericCharacters="0" name="CustSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider"/>
    </providers>
</membership>
<roleManager enabled="true" defaultProvider="CustSqlRoleProvider">
    <providers>
        <add connectionStringName="connString" applicationName="/space_online" name="CustSqlRoleProvider" type="System.Web.Security.SqlRoleProvider"/>
    </providers>
</roleManager>
<anonymousIdentification cookieless="AutoDetect" enabled="true"/>
<profile defaultProvider="CustSqlProfileProvider" enabled="true">
    <providers>
        <add name="CustSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="connString" applicationName="/space_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"/>
            <add name="Fax" type="System.String"/>
        </group>
        <add name="ShoppingCart" type="psb.website.BLL.Store.ShoppingCart" serializeAs="Binary" allowAnonymous="true"/>
    </properties>
</profile>

Code behind

private void UpdateProfile(ProfileCommon myprofile)
{
    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();
}
private ProfileCommon GetProfile()
    {
        ProfileCommon profile = this.Profile;
        if (Request.QueryString["UserName"] != null && HttpContext.Current.User.IsInRole("Admin"))
            profile = this.Profile.GetProfile(Request.QueryString["UserName"].ToString());
        else
            profile = this.Profile.GetProfile(HttpContext.Current.User.Identity.Name);
        return profile;
    }
protected void tbUpdateProfile_Click(object sender, ImageClickEventArgs e)
    {
        UpdateProfile(GetProfile());
    }

解决方案

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.

这篇关于ASP.NET配置文件保存由旧的值覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆