如何在没有ASPNET身份的情况下使用OWIN表单身份验证 [英] How to use OWIN forms authentication without aspnet identity

查看:65
本文介绍了如何在没有ASPNET身份的情况下使用OWIN表单身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用OWIN管道向客户端发出身份验证cookie,在用户注销时清除cookie等,但是我不想使用烦人的aspnet身份提供程序.它只是不适合该项目,我尝试了很长时间,但它并不适合.因此,我决定不使用它.我只想使用OWIN管道.

I want to use the OWIN pipeline to emit the authentication cookie to the client, clear the cookie when the user signs out etc but I don`t want to use the annoying aspnet identity provider. It just doesn't fit on the project, I tried for a long time and it just doesn't fit. So I decide I won't use it. I just want to use the OWIN pipeline.

这是否可行,还是我应该退回旧的表单身份验证?

Is this possible or I should fall back to the old forms authentication?

推荐答案

喜欢吗?

var claims = new List<Claim>();
claims.Add(new Claim(ClaimTypes.Name, "Brock"));
claims.Add(new Claim(ClaimTypes.Email, "brockallen@gmail.com"));
var id = new ClaimsIdentity(claims,
                            DefaultAuthenticationTypes.ApplicationCookie);

var ctx = Request.GetOwinContext();
var authenticationManager = ctx.Authentication;
authenticationManager.SignIn(id);

来自此处.

这篇关于如何在没有ASPNET身份的情况下使用OWIN表单身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆