KB Article T321618
Visible to All Users

Web - How to display the currently logged user name and image in the header bar near the Log Off Action

Description:
I would like to display the current logged on user in the header bar of the new web UI. How to accomplish this task?

Answer:
To accomplish your task, consider one of the following solutions depending on your business requirements and XAF version:

For 16.1.6+ and New Web UI
Use the CurrentUserDisplayImageAttribute and ModelApplicationWeb.CurrentUserDisplayMode  features to achieve the result shown below:

Refer to the XCRM.Web demo app or corresponding product documentation for more details.

For older versions or Classic Web UI
1.  Create and register a custom template content for the main form (use the Default Template Content or Default Vertical Template Content items in the DevExpress Template Gallery) as per the How to: Customize an ASP.NET Template article and add a new table cell with the following code to the markup of the created *.ASCX file, between cells containing the logo and header menu:

ASPx
... <td> <img src="Images/Logo.png" /> </td> <td class="width100"></td> <td><%= DevExpress.ExpressApp.SecuritySystem.CurrentUserName %></td> <td> <div id="xafHeaderMenu" class="xafHeaderMenu" style="float: right;"> ... </td> ...

2.  You can customize the standard MyDetailsController class in the following manner (optionally, customize the corresponding navigation item):

Code
using DevExpress.ExpressApp; using DevExpress.ExpressApp.Actions; using DevExpress.ExpressApp.Security; using DevExpress.ExpressApp.SystemModule; namespace MainDemo.Module {     public class WindowController1 : WindowController {         public WindowController1() {             TargetWindowType = WindowType.Main;         }         protected override void OnActivated() {             base.OnActivated();             string ActionItemId = "MyDetails";             MyDetailsController myDetailsController = Frame.GetController<MyDetailsController>();             if (myDetailsController != null) {                 myDetailsController.Actions[ActionItemId].Caption = SecuritySystem.CurrentUserName;             }             //Optionally, customize the corresponding navigation item.             ShowNavigationItemController showNavigationItemController = Frame.GetController<ShowNavigationItemController>();             if (showNavigationItemController != null) {                 showNavigationItemController.ShowNavigationItemAction.Items.Find(                     ActionItemId, ChoiceActionItemFindType.Recursive, ChoiceActionItemFindTarget.Leaf                 ).Caption = SecuritySystem.CurrentUserName;             }         }     } }


See Also:
Refer to the following help topics for more details on the demonstrated approaches:
How to: Customize an ASP.NET Template.eXpressApp Framework>Concepts>Extend Functionality>Customize Controllers and ActionsWebApplication > SwitchToNewStyle,
ASP.NET Web Application's Appearance

Show previous comments (4)
DevExpress Support Team 8 years ago

    Hello,

    Please run the Model Editor for the ASP.NET module or application project and ensure that the  IModelApplicationWeb.CurrentUserDisplayMode property is set to CaptionAndImage.

    Additionally, if you store the model differences in the database, ensure that this setting is not overridden accidentally at the database level. If this does not help, would you please create a separate ticket and attach a sample project that shows this issue?

    PS: the virtual modifier is not required for the Photo property in an XPO persistent class. An example from the blog you are referring to is for Entity Framework.

    A A
    ADE AAN WIRAMA. 8 years ago

      I did choose CaptionAndImage, but its not working. I'm sure its not overridden at database level.

      Would you please create a separate ticket for me ?

      Thanks

      DevExpress Support Team 8 years ago

        @Ade:

        I've created a separate ticket on your behalf (T513951: Solution provided in T321618 doesn't work in my project). It has been placed in our processing queue and will be answered shortly.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.