asp.net 6 React User.Identity.Name

Kerns, John 1 Reputation point
2022-03-22T15:18:00.25+00:00

We are migrating to React .net 6 from 5. Our apps are internal and we use windows authentication. No issue with this in previous versions getting user.identity.name in a controller with react. I understand the dev environment is working differently. I and another programmer have blogged this issue for a day now and tried many things but are at a point that we cannot get user.identity.name to work in a controller. So could someone give me exact directions on adding this line "var userName = User.Identity.Name" in the Get method on the WeatherForecastController in the default React Template in VS 2022 actually returning something other then null. Thanks .

Developer technologies ASP.NET ASP.NET Core
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-03-22T20:33:28.823+00:00

    I don't believe it is supported in developer mode. when you run dev mode, the .net 6 app starts a node express web server (actually just npm start which does it) to host the react code. the node web server does a reverse proxy to the net 6 webapi server.

    the node express server does not support windows identity.

    if you do publish to IIS and configure windows identity it should work.

    note: this is reverse of .net 5, in which the spa services reverse proxied to the node server. this why windows identity works in .net 5 projects.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.