【问题标题】:ASP.NET c# Profile: GetProfile not avalaible [duplicate]ASP.NET c# 配置文件:GetProfile 不可用 [重复]
【发布时间】:2012-09-29 18:36:19
【问题描述】:

可能重复:
how to use Profile.GetProfile() in a library class?

如何在cs类中获取个人资料?它在 aspx.cs 类中运行良好。

 ProfileCommon profile= HttpContext.Current.Profile.GetProfile(username);

如何使 GetProfile() 在 cs 类中可用?请指教,谢谢

【问题讨论】:

    标签: c# asp.net-membership profile asp.net-profiles


    【解决方案1】:

    看看我关于分析用户的回答。你所需要的都有:

    User profiles in asp.net

    【讨论】:

    • 在您的代码中,您正在创建配置文件,我将如何检索现有配置文件?谢谢
    • 再看看我的回答。首先,您需要在 web.config 中注册配置文件提供程序和配置文件属性。 Create 函数创建配置文件或检索它(如果已存在)。
    • 在您的情况下,您可能缺少配置或 sqlProfile 表(如果您使用的是 SqlProfileProvider)。
    • 你是对的。非常感谢。一旦我将 defaultProvider 更改为 SqlProvider 它就起作用了。情侣请解释一下 AspNetSqlProfileProvider 和 SqlProvider 之间的区别,为什么它不能与 AspNetSqlProfileProvider 一起使用?同样在 aspx.cs 文件中我会使用 GetProfile() 但在类文件中我使用 .ProfileBase.Create(),是一样的吗?我也应该在 aspx.cs 文件中使用 .ProfileBase.Create() 吗?非常感谢。
    • 我认为 AspNetSqlProfileProvider 类型的提供者不存在。这只是用于 SqlProfileProvider 的默认名称。我猜您在更改 web.config 时输入错误。当您想访问特定的配置文件时,只需使用 ProfileBase.Create("SomeUserName") 就可以安全了。只是 ProfileBase.Create() 不会给你你正在寻找的结果。
    猜你喜欢
    • 1970-01-01
    • 2011-07-23
    • 1970-01-01
    • 1970-01-01
    • 2013-03-10
    • 2017-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多