0

I get the current user account ok and manage to remove the domain charters from the output, please see below:

In my HomeController's Index method:

public ActionResult Index(string username)
{    
    ViewBag.UserName = User.Identity?.Name;
    return View();
}

and from my view

<h3>@ViewBag.username.Remove(0, 7)</h3>

All works fine, removes the domain name and just displays the users name e.g. removes corplt/jsmith to just displays "jsmith" - but can this all be done with in the controller or is it ok to have this code within the view? Any help would be greatly appreciated.

Thanks

John.

Mustafa Özçetin
  • 1,893
  • 1
  • 14
  • 16
jbcom41
  • 57
  • 1
  • 6
  • 1
    look to see what other claims are in that `Identity` object – Daniel A. White Apr 24 '23 at 14:51
  • Do you mean you want to access User.Identity in razor view directly? Maybe you can refer to this [link](https://stackoverflow.com/questions/39125347/how-to-get-claim-inside-asp-net-core-razor-view). – Xinran Shen Apr 25 '23 at 05:56

0 Answers0