Link to home
Start Free TrialLog in
Avatar of dodgerfan
dodgerfanFlag for United States of America

asked on

ASP.Net Core MVC display currently logged in user

I have an ASP.Net Core MVC application. I want to display the currently logged in user name. I asked a question earlier about something similar. Here I'm trying to display and grab the current username so that I can pass it to a function later to look up data in a database table with the username in a where clause. But I need to get the username. I've used Environment.UserName before, but it does not work in the .Net core app. I get an error:Environment does not contain a definition for UserName. Thanks.
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

i guess this is a bit vague for your requirements.

what do you mean by "logged in user name"? are you connecting to a database for user authentication?

can you share what you have so far?
Avatar of dodgerfan

ASKER

I'm trying to capture the currently logged in userid or username from windows. I've not done it in a ASP.Net Core MVC application. In other .net applications I've been able to capture it with Environment.UserName, part of the System namespace. I will take the windows userid/username and compare it later to a database table, but first I need to get that windows Id. I hope this clarifies it some.
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My application does not have a web.config file. Putting the code you suggested in does not raise any erors, but when I run it I get the "Hello, " but then it's blank. Where can I set the authentication mode in the app? I have a Startup.cs file.