Hi folks,
I am using asp.net core and I am having problem with docker.
In controller:
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
return new string[] { "value1", "value2" };
}
// GET: api/values/ADUsername
[HttpGet("ADUsername")]
public ActionResult GetADUsername()
{
string userName = WindowsIdentity.GetCurrent().Name.Split('\\').Last();
return Ok(userName);
}
In Window Powershell command:
docker build -t apitest:dev .
docker run -it --rm -p 4200:80 apitest:dev
I run http:/localhost:4200/api/values from browser and It seems ok but if I run http:/localhost:4200/api/values/adusername, I got error message and it says:
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id “0HLNQP40290OI”, Request id “0HLNQP40290OI:00000001”: An unhandled exception was thrown by the application.
System.PlatformNotSupportedException: Windows Principal functionality is not supported on this platform .
at System.Security.Principal.WindowsIdentity.GetCurrent()
at WindowsAuth.Controllers.ValuesController.GetADUsername() in /src/Controllers/ValuesController.cs:line 26
at lambda_method(Closure , Object , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object parameters)
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object arguments)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
if windows principal is not supported then how to get current windows logged username?
I am waiting for your response.
Thanks in advance