2009-10-08 77 views
3

我想在登录时设置一个包含用户时区的cookie。 AccountController.LogOn()似乎是最好的地方。但是,我还不能读取用户的个人资料,因为我猜想只有在方法完成后才能访问配置文件。因此,该代码返回一个空字符串:如何在ASP.NET MVC中获取其他用户的配置文件?

Dim timeZone = HttpContext.Profile("TZ").ToString 

一旦用户已经完全记录在上面的代码返回正确的时区。

一种解决方案是读取配置文件的用户名试图AccountController.LogOn(2)登录:

ProfileCommon profile = Profile.GetProfile(username); // FAILS 

但是,这是行不通的。

那么,如果他们没有登录,我该如何阅读给定用户的个人资料?

+0

Profile.GetProfile如何失败?什么是例外? – 2009-10-08 07:25:27

+0

Profile.GetProfile()似乎不适用于MVC应用程序。 – royco 2009-10-08 07:28:48

回答

8

这并不看起来很明显,但为获得简介:

ProfileBase profile = ProfileBase.Create(HttpContext.Profile.UserName, true); 

返回现有的实例。

+0

谢谢。我知道ProfileBase.Create(),但我认为它为没有用户的用户创建了新的配置文件。 – royco 2009-10-08 15:18:47

1

除了马蒂亚斯的回答,您可以将其投放到您输入的个人资料:

ProfileCommon profile = (ProfileCommon)ProfileBase.Create(username, true); 

而且,ProfileBase.Create的文件是MSDN上。

+0

谢谢你。 – royco 2009-10-08 15:19:26

相关问题