Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Chris Koiak 700 posts 2626 karma points
    Apr 05, 2012 @ 11:53
    Chris Koiak
    0

    Get Current User in Umbraco5.1

    Hi,

    What's the best way to get the current logged in member in Umbraco 5.1?

    I'm currently using

         string username = User.Identity.Name;
         Umbraco.Framework.Security.Model.Entities.Member currentMember = RoutableRequestContext.Application.Security.Members.GetByUsername(username);
  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Apr 05, 2012 @ 12:10
    Morten Bock
    1

    Where are you trying to get it? Surface controller or Razor?

    In razor you can do 

    @{
    Member current = Umbraco.Members.GetCurrent();
    }

    In a controller you can get the context in your constructur and use that

    public class MyController : Controller
    {
    private readonly IUmbracoApplicationContext _context; public MyController(IUmbracoApplicationContext context) { _context = context; }

    [HttpGet] public ActionResult DoStuff() {
    var member = _context.Security.Members.GetCurrent();
    } } 
  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Apr 05, 2012 @ 12:13
    Morten Bock
    0

    Hmm. Was that answer accepted extremely fast, or did it somehow happen when I edited my post?

  • Chris Koiak 700 posts 2626 karma points
    Apr 05, 2012 @ 12:38
    Chris Koiak
    0

    The answer was ideal! Thanks Morton

    A fast response deserves a fast hy5!

Please Sign in or register to post replies

Write your reply to:

Draft