2009-09-19 51 views
2

我想更改现有用户的配置文件,而无需为用户创建新配置文件。例如:我有一个用户名Usr1,我只想改变他的年龄,我该怎么做?更新ASP.NET中的现有用户配置文件

+0

您使用的是什么技术? – 2009-09-19 12:45:33

回答

2

this文章的全部细节。请注意,在某些情况下(请参阅我对其他答案的评论),ProfileCommon不会生成。

在这种情况下,你需要恢复使用ProfileBase:

ProfileBase profile = context.Profile; 
DateTime dob= profile.GetPropertyValue("dob") as DateTime; 
... 
profile.SetPropertyValue("dob",dob); 
1

如果你看看this article,它说明了如何做到这一点...

+0

如果这是一个** web应用程序**(认为是Asp.net MVC),那么ProfileCommon不是自动生成的,您必须恢复到非类型安全的ProfileBase – spender 2009-09-19 12:07:58

3

当你在你的页面提供给您的ProfileCommon类用于访问配置文件。 profilecommon类是在编译web项目期间由web.net自动从web.config配置文件设置生成的。

如果您想使用app_code文件夹中的配置文件,则必须使用profilebase类。 Profilecommon在页面中可用也来自此类。

Profilebase可就是这样

HttpContext.Profile or HttpContext.Current.Profile 

访问要读你需要做的概况值以下

HttpContext.Profile.GetPropertyValue("propertyName"); 

要将值写入到你需要写

HttpContext.Profile.SetPropertyValue("propertyName", "propertyValue"); 
轮廓
2

如果你想要做的是更新另一个用户的个人资料(例如,你是一个管理员输入一个客户的用户名),你可以使用类似下面的内容。

Dim p As ProfileCommon = Profile.GetProfile("Usr1") 

p.TestValue1 = "New Value" 
p.TestValue2 = "Another New Value" 

p.Save() 

同样,如果你使用的是web项目,而不是一个网站,你将不得不使用p.SetPropertyValue(),而不是强类型的属性名称。

-1

我有一个类似的问题,并与SQL脚本搜索解决方案。这有点困难,但如果服务器端代码不是一个选项,这是可行的。 我设置两个字段dbo.aspnet_Profile(PropertyValuesString,PropertyNames)

UPDATE dbo.aspnet_Profile 
SET 
PropertyValuesString = cast(Replace(cast(PropertyValuesString as nvarchar(max)),'New Value','Old Value') as ntext) 
,PropertyNames='New calculated property names' 
WHERE 
UserId='userID' 

困难的部分是改变PropertyNames field.It包含对配置文件名称属性,起始位置和长度。类似的东西:地址:S:31:12 您必须重新计算开始位置和长度相应的新值。