更新 ASP.NET 中现有用户的配置文件
我想更改现有用户的配置文件,而不必为该用户创建新的配置文件。例如:我有一个用户名 Usr1
,我只想更改他的年龄,我该怎么做?
I want to change an existing user's profile without having to create a new profile for the user. For example: I have a user name Usr1
and I want to change only his age, how do I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当您进入该页面时,您可以使用 ProfileCommon 类来访问配置文件。 profilecommon 类是在 Web 项目编译期间由 ASP.NET 根据您的 web.config 配置文件设置自动生成的。
如果您想使用 app_code 文件夹中的配置文件,则必须使用 profilebase 类。页面中可用的 Profilecommon 也派生自此类。
Profilebase 可以像这样访问
要读取配置文件值,您需要执行以下操作
要将值写入您需要写入的配置文件
When you are in the page you have the ProfileCommon class available to you for accessing the profile. The profilecommon class is automatically generated by asp.net from you web.config profile settings during compilation of the web project.
In case you want to use the profile from app_code folder, you will have to use the profilebase class. Profilecommon that is available in the page also derives from this class.
Profilebase can be access like this
To read a profile value you need to do the following
To write a value to the profile you need to write
有关完整详细信息,请参阅本文文章。请注意,在某些情况下(请参阅我对另一个答案的评论),不会生成 ProfileCommon。
在这种情况下,您需要恢复使用 ProfileBase:
See this article for the full details. Be aware that in certain cases (see my comment to another answer), ProfileCommon is not generated.
In this case you need to revert to using ProfileBase:
如果您尝试执行的是更新他人的用户个人资料(例如,您是输入客户用户名的管理员),则可以使用类似以下内容的内容。
同样,如果您使用的是 Web 项目而不是网站,则必须使用 p.SetPropertyValue() 而不是强类型属性名称。
If what you are trying to do is update another's user profile (say, you are an admin who types in a customer's username), you can use something like the following.
Again, if you are using a web project instead of a web site, you will have to use p.SetPropertyValue() instead of the strong-typed property names.
我有一个类似的问题并使用sql脚本搜索解决方案。这有点困难,但在服务器端代码不可行的情况下也是可行的。
我在 dbo.aspnet_Profile (PropertyValuesString, PropertyNames) 中设置了两个字段,
困难的部分是更改 PropertyNames 字段。它包含配置文件名称属性、起始位置和长度。类似的东西:地址:S:31:12
您必须相应地重新计算起始位置和长度新值。
I have a similar problem and search for solution with sql script. It is little bit more difficult but it is doable in case server side code is not an option.
I set two fields in dbo.aspnet_Profile (PropertyValuesString, PropertyNames)
Difficult part is to change PropertyNames field.It contains profile name property, start position, and length. Something like that : address:S:31:12
You have to recalculated start positions and lengths accordingly new value.