I am trying to display the currently logged in user name or login name for the currently logged in member. Such as you might do if you wanted the page to say Hello Connie. I cannot reliably get my member data. It seems to be displaying the information for the last person who logged into my site. How do I correctly display this in my Razor file?
I have this currently:
@using umbraco.cms.businesslogic.member
You are logged in as @Member.GetCurrentMember().LoginName.ToString()
If want some thing that says you are logged in as Your name then you should take a look at the built in Login Status Razor code snippet.
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using System.Web.Mvc.Html
@using ClientDependency.Core.Mvc
@using Umbraco.Web
@using Umbraco.Web.Models
@using Umbraco.Web.Controllers
@{
var loginStatusModel = Members.GetCurrentLoginStatus();
Html.EnableClientValidation();
Html.EnableUnobtrusiveJavaScript();
Html.RequiresJs("/umbraco_client/ui/jquery.js");
Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
var logoutModel = new PostRedirectModel();
@*
Here you can specify a redirect URL for after logging out, by default umbraco will simply
redirect to the current page. Example to redirect to the home page:
logoutModel.RedirectUrl = "/";
*@
}
@* NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed *@
@Html.RenderJsHere()
@if (loginStatusModel.IsLoggedIn)
{
<p>You are currently logged in as @loginStatusModel.Name</p>
using (Html.BeginUmbracoForm<UmbLoginStatusController>("HandleLogout"))
{
<fieldset>
<legend>Logout</legend>
<button>Logout</button>
</fieldset>
@Html.HiddenFor(m => logoutModel.RedirectUrl)
}
}
How to display Member Name in Razor
I am trying to display the currently logged in user name or login name for the currently logged in member. Such as you might do if you wanted the page to say Hello Connie. I cannot reliably get my member data. It seems to be displaying the information for the last person who logged into my site. How do I correctly display this in my Razor file?
I have this currently:
@using umbraco.cms.businesslogic.member
You are logged in as @Member.GetCurrentMember().LoginName.ToString()
Hi Connie,
If want some thing that says you are logged in as Your name then you should take a look at the built in Login Status Razor code snippet.
Hope this helps,
/Dennis
Hi, Connie.
The most succinct approach I've found is to use the Umbraco MembershipHelper (see the documentation here).
Your code in the view might look something like this:
Where Members is a reference that automatically ships with your UmbracoViewPage.
is working on a reply...