我在网站中使用ASP.NET的配置文件功能。更新个人资料很奇怪!用户不能更新他/她自己的个人资料,无论是网站用户还是管理员,但管理员可以更新其他用户的个人资料。
在后端,调用 Profile 的 save() 后,SQL Server 跟踪显示aspnet_Profile_SetProperties存储过程被调用了两次。首先是新的价值观,然后是旧的价值观。第二次执行是在页面卸载后完成的。我的代码与交易无关。
为什么它的工作如此奇怪?
aspnet_regsql的安装可能有问题,因为我已经卸载并再次安装它!?
代码
网络配置
<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());
}