0

I created a selfhosting webapp (Microsoft.AspNetCore.Owin) as recommended in stackoverflow by @Anouar.

It works as expected. But I can't get user information from the context. There doesn't seem to be any Claim in HttpContext.Users.Claims (nrOfClaims = 0).

public class SayHi : ControllerBase
{
    [Route("sayhi/{name}")]
    public IActionResult Get(string name)
    {
        var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;

        var nrOfClaims = HttpContext.User.Claims.Count();

Is it possible to get the username and the user-domainname via HttpContext here?

I searched various sites. I tried IHttpContextAccessor stackoverflow via constructor dependency injection. But the HttpContextAccessor seems to be the same as HttpContext itself.

burnsi
  • 6,194
  • 13
  • 17
  • 27
  • What authentication mechanism are you using – Daniel A. White Jan 20 '23 at 08:47
  • There is no authentification. I will use it as a local webserver in a windows service. Is it in principle possible to get the local username and domainname of the user, who sends a get or post request without authentication? – Alexander Ausweger Jan 20 '23 at 13:25
  • You have to enable windows authentication to get that information – Daniel A. White Jan 20 '23 at 13:37
  • So if i understood that correctly, without any additional authentication i.e. user logs in in some way, i can't get the doman and username of the user who sent a get or a post from a browser in the httpcontext? – Alexander Ausweger Jan 25 '23 at 09:18

0 Answers0