Is it possible to change a string from another model, basically we have a simple login page which takes the username and then directs you back to the index main page and should display "Welcome (USER)", I want the (USER) to be the username of which was entered in the login form.
I know you can just RedirectToPage("/Index", new {Login.Username}); but this would make the URL change with the username and if you change the URL it changes the username on the page.
Is there a way to change the string in a controller or model from the OnGet()?
I've tried to change it but it comes up with the username string being null but it would be because the user has not set this yet and it won't let me start it up.
CodePudding user response:
<div id="UserName" >username: @User.Identity.Name</div>
you can use this piece of code in your razor view (.cshtml
) but you should make sure you have stored the username in a cookie with a Claim (if you are using asp.net core identity it stores the username cookie for you automatically)