配置文件内容检查是否设置?

发布于 2024-09-07 20:53:15 字数 122 浏览 5 评论 0原文

使用 asp.net 配置文件,我存储了一个复杂类型(类)并检索了它。但它返回的是一个未初始化的新对象而不是 null?这是预期的行为吗?如果是,我如何确定是否已为给定用户保存数据?

应该是一些容易让人掌握的要点。

Using asp.net profiles, I've stored a complex type (class) and retrieved it. But it is returning a new object that is not initialized instead of null? Is this the expected behavior, if so how can I determine if I've saved data for the given user?

should be some easy points for someone to pick up..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

说谎友 2024-09-14 20:53:15

您的问题有点不清楚,但我认为您是在问为什么您尚未为其存储数据的用户有一个非空配置文件数据对象?

本文可能会为您澄清这一点。一些相关的位:

用户个人资料是以下内容的集合
ASP.NET 2.0 运行时的值
组作为 a 的公共字段
动态生成的类。班级
源自系统提供的
类并扩展为
增加了一些新成员。这
类不必标记为
可序列化,但其内容是
持久保存到存储介质上
个人财产。存储
发生在每个用户的基础上,并且是
保留到管理员为止
删除它。

再往下:

当应用程序运行并且出现页面时
显示,ASP.NET动态
创建一个配置文件对象,其中包含
正确输入数据并分配
登录用户的当前设置
数据中定义的属性
模型。配置文件对象已添加到
当前的 HttpContext 对象和
通过以下方式可供页面使用
配置文件属性。假设
配置文件模型已定义为
将链接列表存储为集合,
下面的代码片段展示了如何
检索收藏夹链接列表
由给定用户创建:

...

此代码假定 Links 属性为
引用 a 的配置文件对象
集合类型。当页面是
已加载,链接和其他属性是
初始化为包含最多
最近存储的值;当页面
已卸载,其当前内容是
存储到持久介质。

如果您需要跟踪用户之前是否设置过配置文件数据,您可以使用 FindProfilesByUserName 函数用于在登录之前检查配置文件是否存在。

Your question is a little unclear, but I think you're asking why there's a non-null profile data object for a user who you haven't stored data for yet?

This article might hopefully clear it up for you. Some of the relevant bits:

A user profile is a collection of
values that the ASP.NET 2.0 runtime
groups as public fields of a
dynamically generated class. The class
is derived from a system-provided
class and is extended with the
addition of a few new members. The
class doesn't have to be marked as
Serializable, however its contents are
persisted to the storage medium as
individual properties. The storage
occurs on a per-user basis and is
preserved until an administrator
deletes it.

And further down:

When the application runs and a page
is displayed, ASP.NET dynamically
creates a profile object that contains
properly typed data and assigns the
current settings for the logged user
to the properties defined in the data
model. The profile object is added to
the current HttpContext object and
made available to pages through the
Profile property. Assuming that the
profile model has been defined to
store a list of links as a collection,
the following code snippet shows how
to retrieve the list of favorite links
that are created by a given user:

...

This code assumes a Links property in
the profile object that references a
collection type. When the page is
loaded, Links and other properties are
initialized to contain the most
recently stored values; when the page
is unloaded their current contents are
stored to the persistent medium.

If you need to track whether a user has ever set profile data before, you might be able to use the FindProfilesByUserName function to check to see if a profile exists before you log them in.

叹倦 2024-09-14 20:53:15

有点晚了,但是 UsingDefaultValue 告诉您属性值是来自用户配置文件设置还是使用默认值。另一种可以获得相同结果的方法是使用 反序列化

A little late, but UsingDefaultValue tells you if the property value is coming from the user profile settings or if it's using a default. Another way you can get, kind of, the same result is using Deserialized.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文