The OnActionExecuting
method is fired before every Action in a MVC controller. You can use this method to set and retrieve variables that are useful throughout your session, such as the person’s name, their profile photo, etc.
The following is an example implementation of this method
public class HomeController : Controller { protected override void OnActionExecuting(ActionExecutingContext ctx) { base.OnActionExecuting(ctx); using (Repository rep = new Repository()) { if (Request.IsAuthenticated) { var profile = rep.GetProfileByID((Guid)Membership.GetUser().ProviderUserKey); ViewBag.Name = profile.DisplayName; } } } public ActionResult Index() { //your code return View(); } //rest of your methods }
Quick Links
Legal Stuff