开发者

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

开发者 https://www.devze.com 2022-12-08 04:15 出处:网络
I want to set a cookie with a user\'s timezone when they login.AccountController.LogOn() seems like the best place to do this.However, I can\'t yet read a user\'s profile there since I guess you only

I want to set a cookie with a user's timezone when they login. AccountController.LogOn() seems like the best place to do this. However, I can't yet read a user's profile there since I guess you only have access to profiles when the method completes. So, this code returns an empty string:

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

Once a user has fully logged on, the above code returns the correct TimeZone.

One solution is to read the profile for the username trying to log on in AccountController.LogOn():

ProfileC开发者_如何学Common profile = Profile.GetProfile(username);  // FAILS

However, this doesn't work.

So, how do I read a given user's profile if they're not logged in?


this doesnt look obvious but is a get Profile:

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

returns an existing instance.


In addition to Mathias' answer, you can then cast it to your typed profile:

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

Also, the documentation for ProfileBase.Create is on MSDN.

0

精彩评论

暂无评论...
验证码 换一张
取 消