This is often something that is never apparent but can improve performance. On the master page, you need to make a call, for example, to get the MembershipUser.
MembershipUser user = Membership.GetUser();
Then on the page you need to do the same so you copy the code again. This results in two calls. For a current project, this means two WCF calls so there is a significant latency added to page rendering. A better solution is to make the User public on the master page and then use it (and avoid the second call).
On the master page, change it to a self-initializing property (and avoid putting initialization into events like Page_Load)
MembershipUser _User
public MembershipUser User
{
get
{
if (_User == null)
{
_User = Membership.GetUser();
}
return _User;
}
}
protected void Page_Load(object sender, EventArgs e)
{
var user = ((MyUserPortal.AppMasters.Default)Master).User;
}
You have eliminated a call with little effort and improved performance.
Bottom line, be aware of what is in the Master Page and strive to re-use what is there.
No comments:
Post a Comment