【问题标题】:Custom Profile Provider with class library具有类库的自定义配置文件提供程序
【发布时间】:2010-07-26 19:32:38
【问题描述】:

我有一个类库(我们称之为 a),我在其中创建了一个自定义配置文件提供程序。我在另一个类库中引用了这个库(我们称之为 b),它是与 Web 应用程序一起解决方案的一部分.现在我如何引用类库 b 中的自定义配置文件提供程序。

我一直在关注这篇文章http://leedumond.com/blog/getting-strongly-typed-profile-properties-from-a-class-library。没关系,但它不会保存仅读取它的配置文件。

有没有人做过或者知道怎么做?

【问题讨论】:

    标签: asp.net profile class-library web-applications


    【解决方案1】:

    这个例子并不是你真正想要的。

    一旦您创建了一个继承 ProfileBase 的 ProfileCommon,请使用该类的实例来管理它。

    所以:

    ProfileCommon profile = (ProfileCommon)HttpContext.Current.Profile;
    profile.Name = "balstedfury";
    Profile.Save();
    

    由于 ProfileCommon 继承了 ProfileBase,您可以调用 Save 来记录它。见http://msdn.microsoft.com/en-us/library/system.web.profile.profilebase_members.aspx

    告诉我这有帮助。

    【讨论】:

    • ProfileCommon 是动态创建的,不是吗?并且在类库中您无法访问它。
    • 实际上 ProfileCommon 可以被实例化,因为它是公共的。为此,您需要在应用程序中引用该库。如果您仅使用配置,而不是您的情况,我相信它是动态创建的。但是你需要告诉你的配置文件配置是它的配置文件的类型。如果我没记错的话,它是 profile 元素的一个属性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-05
    • 2019-01-29
    • 2022-08-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多