如何在库类中使用 Profile.GetProfile() ?
我不知道如何在库类中使用 Profile.GetProfile()
方法。 我尝试在 Page.aspx.cs 中使用此方法,效果非常好。
我怎样才能制作一个在 page.aspx.cs 中工作的方法,在类库中工作。
I cant figure out how to use Profile.GetProfile()
method in a library class.
I tried using this method in a Page.aspx.cs and it worked perfectly.
How can I make a method that works in the page.aspx.cs, work in the class library.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 ASP.NET 中,Profile 是 HttpContext 的挂钩.Current.Profile 属性,返回动态生成的 ProfileCommon 类型的对象,派生自 System.Web.Profile.ProfileBase。
ProfileCommon 显然包含一个 GetProfile(string username) 方法,但您不会在 MSDN 中找到它的正式记录(并且它不会显示在 Visual Studio 的智能感知中),因为大多数 ProfileCommon 类是在编译 ASP.NET 应用程序时动态生成的(属性和方法的确切列表将取决于 web.config 中“配置文件”的配置方式)。 GetProfile() 确实在此 MSDN 上得到提及页,所以它看起来是真实的。
也许在您的库类中,问题是没有获取来自 web.config 的配置信息。您的库类是包含 Web 应用程序的解决方案的一部分,还是您只是单独处理该库?
In ASP.NET, Profile is a hook into the HttpContext.Current.Profile property, which returns a dynamically generated object of type ProfileCommon, derived from System.Web.Profile.ProfileBase.
ProfileCommon apparently includes a GetProfile(string username) method, but you wont find it documented officially in MSDN (and it wont show up in intellisense in visual studio) because most of the ProfileCommon class is dynamically generated when your ASP.NET application is compiled (The exact list of properties and methods will depend on how 'profiles' are configured in your web.config). GetProfile() does get a mention on this MSDN page, so it seems to be real.
Perhaps in your library class, the problem is that the configuration info from web.config is not being picked up. Is your library class part of a Solultion that includes a Web Application, or are you just working on the library in isolation?
您是否尝试将对
System.Web.dll
的引用添加到您的类库中,然后:Have you tried adding reference to
System.Web.dll
to your class library and then:您可以使用 ProfileBase,但会失去类型安全性。您可以通过仔细的转换和错误处理来缓解这种情况。
You can use ProfileBase, but you lose type-safety. You can mitigate that with careful casting and error handling.