After a user logs into your application, you want to display a personalized greeting like "Welcome, [Username]!". How can you fetch the username of the currently logged-in user in ASP.NET Core?
- Use HttpContext.User.Identity.Name
- Query the database for the username
- Prompt the user to enter their username after login
- Use a hardcoded username
In ASP.NET Core, you can fetch the username of the currently logged-in user by accessing HttpContext.User.Identity.Name. This property contains the username of the authenticated user, allowing you to display a personalized greeting like "Welcome, [Username]!".
Loading...
Related Quiz
- What is the primary purpose of the [Authorize] attribute in ASP.NET Core?
- If a developer is looking to quickly scaffold a new ASP.NET Core controller, which CLI command would they most likely use?
- Application-specific settings, such as connection strings, can be added to the ________ file.
- In a project where user registration is done programmatically, you want to ensure that users have a strong password and are locked out after 5 incorrect login attempts. Which class should you configure to enforce these rules?
- Which of the following is a built-in Razor Tag Helper in ASP.NET Core?