3
votes

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():

ProfileCommon 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?

2
How does Profile.GetProfile fail? What is the exception?Richard Szalay
Profile.GetProfile() doesn't appear to exist for MVC apps.royco

2 Answers

8
votes

this doesnt look obvious but is a get Profile:

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

returns an existing instance.

1
votes

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.