我在网站上使用
ASP.NET的个人资料功能.更新配置文件很奇怪!用户无法更新他/她自己的个人资料,无论是网站用户还是管理员,管理员都无法更新其他用户的个人资料.
在后端,调用Profile的save()后,sql Server跟踪显示aspnet_Profile_SetProperties存储过程被调用两次.首先,使用新值,使用旧值.第二次执行是在页面卸载后完成的.我的代码与事务无关.
为什么这么奇怪?
aspnet_regsql的安装是否存在问题,因为我已经安装了已卸载并再次安装它!?
码
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>
代码背后
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()); }
解决方法
默认情况下,配置文件会在ASP.NET页面执行结束时自动保存,请参阅
profile Element (ASP.NET Settings Schema)文档.这解释了你观察到的第二个“神秘”的拯救.
您可以尝试将automaticSaveEnabled更改为false.