0

I have a MVC project, and I'm using IHttpContextAccessor in order to use HttpContext in my controller.

public RequestController(IHttpContextAccessor accessor)
{
  _contextAccessor = accessor;
}

I use another function in order to find out the name of the user that in the website. So, I create a HTTP request, and then I get the user name in that way: _contextAccessor.HttpContext.User.Identity.Name

In debug mode everything look fine and when I'm routing to: localhost/user I get my user name, but when it's not debug mode and it's locally or from IIS it just return NULL.
Anyone have an idea why?

Steeve
  • 1
  • 2
  • What exactly is the authentication method you set on IIS/IIS Express and ASP.NET Core? Different settings do lead to different results. Learn what are the configuration files involved and edit the question to include critical lines from those files. – Lex Li Nov 30 '22 at 16:08
  • Thabnks. Finally I understood that I need to disable anonymous authentication from the server in IIS. – Steeve Nov 30 '22 at 17:10

1 Answers1

0

Finally I understood that I need to disable anonymous authentication from the server in IIS.

Authentication in the server

Change to disabled

Steeve
  • 1
  • 2