繁体   English   中英

如何在ASP.NET MVC中获取另一个用户的配置文件?

[英]How to get another user's profile in ASP.NET MVC?

我想在登录时设置一个用户时区的cookie。 AccountController.LogOn()似乎是最好的地方。 但是,我还不能在那里读取用户的配置文件,因为我猜你只能在方法完成时访问配置文件。 所以,这段代码返回一个空字符串:

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

用户完全登录后,上面的代码将返回正确的TimeZone。

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

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

但是,这不起作用。

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

这看起来并不明显,但是获得一个简介:

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

返回现有实例。

除了Mathias的答案,您还可以将其转换为您键入的配置文件:

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

此外, ProfileBase.Create的文档位于MSDN上。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM