Hey, I am a very first time write very long time readers of the site.

I am building an .Internet MVC site, using ProfilBase to keep a custom user object. The profile is made of saved with an database on some other server compared to webserver. I've an assistant class, UserInfoHelper that consists of static approach to retrive username, email, telephone etc.

At this time a means to for examlpe get retive the e-mail address appears like this:

  public static String GetEmail()
    {
        ProfileBase profileBase = HttpContext.Current.Profile as ProfileBase;
        UserObject user = (UserObject)profileBase.GetPropertyValue("UserObject");
        return user.PrimaryEmail;
    }

And from the view i give them a call such as this:

<%= UserInfoHelper.GetEmail() %>

So for every time after i call a technique within the assistant class the consumer is fetch in the db. I wish it to just fetch it once for every user when loged in or att least once per response. What's the ultimate way to get this done.

Is also there a good way to obtain the default ProfileBase using web services rather than calling the saved methods direcly?

Thank you ahead of time.

I'm able to concur using what @Paul just responded...

Use cases such as these be more effective handled with controller actions which return an incomplete view that you would render user information. You'd send a whole UserObject instance (or ViewModel representation from it) towards the View and also have the View strongly typed to that particular class. Then, if the would still represent performance problem, you can cache the controller action output by utilizing OutputCache characteristics the loop. This is actually the prefered method of doing things in ASP.Internet MVC.

If, however, you've got a page in which you need plenty of information from across different business domain objects, you may make composite View Model classes such as this:

public class DashboardViewModel
{
    public UserObject User { get; set; }
    public BusinessData BizData { get; set; }
    public FirmObject Firm { get; set; }
}

Inside your view page, starting with this line

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MyNamespace.DashboardViewModel>" %>

you'll be able to render out everything from DashboardViewModel you've delivered to the page such as this:

<%: Model.User.Firstname %>

or

<%: Model.BizData.SalesTotal %>

I am just causeing this to be up here but this really is generally how it ought to be done.

I believe the problem is how you are utilizing MVC above all else. You're utilizing a call to some assistant method directly inside your web site. Instead of carrying this out you need to hands this processing off and away to controller or code that calls (some way) after which include that towards the model and employ something similar to <%=Model.Email%> within the view

After you have this model implemented you'd curently have the processing only making the phone call once per request. At that point you are able to profile the application and find out if any more optimisation is required. Options accessible to you then will be to wrap the retrieval from the current email address in certain kind of caching that may persist between calls. But that is only when it's needed - you may be optimising prematurely because the overhead of just calling it once per request might be acceptable.