locked
windows authentication RRS feed

  • Question

  • User-297906461 posted

    hi 

    i have mvc core 2 project without authentication. i wanna get windows  user name in controller. 

    i tray to add

    var user = User.Identity.Name;
    

    but that doesn't work. i think that because my web application with no authentication

    how i can solve this problem 

    thanks

    Friday, November 2, 2018 8:58 AM

All replies

  • User283571144 posted

    Hi ohoud,

    ohoud

    but that doesn't work. i think that because my web application with no authentication

    how i can solve this problem 

    As you said, we couldn't get the user name if you don't enable the windows auth in your asp.net core application, since you don't know which user access your application.

    If you want to enable the windows auth in the your mvc application in asp.net core.

    I suggest you could try to use below way:

    Find the launchSettings.json in your application and add below settings:

        "windowsAuthentication": true, 
        "anonymousAuthentication": false, 

    Whole launchSettings.json:

    {
      "iisSettings": {
        "windowsAuthentication": true, 
        "anonymousAuthentication": false, 
        "iisExpress": {
          "applicationUrl": "http://localhost:65373",
          "sslPort": 44322
        }
      },
      "profiles": {
        "IIS Express": {
          "commandName": "IISExpress",
          "launchBrowser": true,
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
          }
        },
        "AspCoreWinAuth": {
          "commandName": "Project",
          "launchBrowser": true,
          "applicationUrl": "https://localhost:5001;http://localhost:5000",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
          }
        }
      }
    }

    launchSettings Image:

    Result:

    Best Regards,

    Brando

    Wednesday, November 14, 2018 9:06 AM