# Keycloak integration with ASP.NET (MVC), IsAuthenticated is always false

**URL:** <https://forum.keycloak.org/t/keycloak-integration-with-asp-net-mvc-isauthenticated-is-always-false/18652>\
**Category:** Miscellanaeous\
**Created:** [November 28, 2022, 3:53pm UTC](https://forum.keycloak.org/t/keycloak-integration-with-asp-net-mvc-isauthenticated-is-always-false/18652 "2022-11-28T15:53:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cebugdev](https://avatars.discourse-cdn.com/v4/letter/c/97f17d/32.png) [@cebugdev](https://forum.keycloak.org/u/cebugdev)\
**Post date:** [November 28, 2022, 3:53pm UTC](https://forum.keycloak.org/t/keycloak-integration-with-asp-net-mvc-isauthenticated-is-always-false/18652/1 "2022-11-28T15:53:46Z")

</div>

I have succesfuly integrated Keycloak into my [ASP.NET](http://ASP.NET) MVC application like so

```auto
            const string persistentAuthType = "keycloak_auth";

            app.SetDefaultSignInAsAuthenticationType(persistentAuthType);
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = persistentAuthType,
            });

            // Configure Auth0 authentication
            app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
            {
                AuthenticationType = "keycloak_auth",
                ClientId = clientId,
                Authority = authorityserver,
                RedirectUri = "http://localhost:13636/home",
                PostLogoutRedirectUri = "http://localhost:13636",
                ClientSecret = clientSecret,
                RequireHttpsMetadata = false,
               
                ResponseType = OpenIdConnectResponseType.Code,
                Scope = "openid profile email",

            });

```

The test is ok, the Keycloak login page is displayed and i can login to it and it redirects to my /home controller correctly, however in the Home controller, when checking the User.Identity.IsAuthenticated it always return to false;

```auto
public class HomeController : BaseController
    {
        public ActionResult Index()
        {
            if (!User.Identity.IsAuthenticated) // <-- always false
            {
                HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties
                {
                    RedirectUri = Url.Action("Index", "Home")
                }, "keycloak_auth");
                return new HttpUnauthorizedResult();
            }
            ViewBag.Title = "Home";
            return View();
        }

```

Why is this? Am I missing something? since it is false, it always calls it back  
/home and landing on the same conditions inside the IsAuthenticated (false) thus “crashing” since it overruns stack.

Anyone can help?
