c#owin can';登录后无法获取用户身份

c#owin can';登录后无法获取用户身份,c#,owin,claims-based-identity,asp.net-identity-2,C#,Owin,Claims Based Identity,Asp.net Identity 2,在我完成登录代码之后 var identity = new ClaimsIdentity(claims, OAuthConfigur.AuthenticationType); this.AuthenticationManager.SignIn(new AuthenticationProperties { ExpiresUtc = DateTimeOffset.Now.AddMinutes(30),

在我完成登录代码之后

        var identity = new ClaimsIdentity(claims, OAuthConfigur.AuthenticationType);

        this.AuthenticationManager.SignIn(new AuthenticationProperties
        {
            ExpiresUtc = DateTimeOffset.Now.AddMinutes(30),
            IsPersistent = false
        }, identity);

        return RedirectToAction("Index", "Home");
重定向到操作后,broswer中有cookie。
但当使用Authorize属性时,没有授权。
在我的自定义过滤器中

httpContext.User.Identity.IsAuthenticated
总是返回false

我在下面找到了获得身份的方法:

    private ClaimsIdentity GetIdentity(HttpContextBase httpContext)
    {
        var ticket = httpContext.GetOwinContext().Authentication
                .AuthenticateAsync(OAuthConfigur.AuthenticationType).Result;
        var identity = ticket != null ? ticket.Identity : null;
        return identity;
    }
在这个函数之后,我可以获得useridentity

这是正确的吗

如果我需要用户登录信息,我需要在每次操作时调用此函数

谢谢回复

这是我的Startup.cs

 public void ConfigureAuth(IAppBuilder app)
    {
        // Enable Application Sign In Cookie
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = OAuthConfigur.AuthenticationType,
            AuthenticationMode = AuthenticationMode.Passive,
            LoginPath = new PathString(OAuthPaths.LoginPath),
            LogoutPath = new PathString(OAuthPaths.LogoutPath),
            ExpireTimeSpan = TimeSpan.FromMinutes(20)
        });

        // Setup Authorization Server
        app.UseOAuthAuthorizationServer(new CustomerOAuthAuthorizationServerOptions());
    }

以防将来有人偶然发现。我也有同样的问题,当我意识到我已经设定了目标的时候,我正在发疯

CookieSecure = CookieSecureOption.Always
在CookieAuthenticationOptions类上:/


很明显,cookie只能通过https进行访问,因为我的本地环境没有使用https(过去是这样)进行设置,所以它无法读取cookie。

以防将来有人偶然发现这一点。我也有同样的问题,当我意识到我已经设定了目标的时候,我正在发疯

CookieSecure = CookieSecureOption.Always
在CookieAuthenticationOptions类上:/


很明显,cookie只能通过https进行访问,因为我的本地环境没有使用https(过去是)进行设置,所以它无法读取cookie。

当将应用程序发布到生产服务器时,我有一个场景,即调用httpContext.GetOwinContext()。身份验证
.AuthenticateTasync(“应用程序”)在IE浏览器中始终返回null。对于这种情况,请转到IE浏览器Internet选项->受信任站点,将您的identity server应用程序url添加为受信任站点。然后系统工作。

当将应用程序发布到生产服务器时,我有一个场景:调用httpContext.GetOwinContext().Authentication
.AuthenticateTasync(“应用程序”)在IE浏览器中始终返回null。对于这种情况,请转到IE浏览器Internet选项->受信任站点,将您的identity server应用程序url添加为受信任站点。然后系统工作。

给我们看你的
Startup.Auth.cs
文件给我们看你的
Startup.Auth.cs
文件我试过你的建议,但不走运。甚至当我尝试CookieSecureOption.SameAsRequest时,也没有任何消息。嗯,我试过你的建议,但我运气不好。甚至当我尝试CookieSecureOption.SameAsRequest时,也没有任何消息。隐马尔可夫模型