Asp.Net 5(Mvc 6)中的Custom ClaimsPrincipal [英] Custom ClaimsPrincipal in Asp.Net 5 (Mvc 6)

查看:61
本文介绍了Asp.Net 5(Mvc 6)中的Custom ClaimsPrincipal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何覆盖Asp.Net 5(MVC-6)中类型为System.Security.Claims.ClaimsPrincipal的默认Context.User?

How can I override the default Context.User of type System.Security.Claims.ClaimsPrincipal in Asp.Net 5 (MVC-6)?

我想使用自定义的用户类型,以便可以在Controllers(HttpContext.User)以及Razor视图(@User.)中访问它

I would like to use my customized User-type, so that it's accessible in Controllers (HttpContext.User), as well as in the Razor views (@User.)

我们非常感谢您的帮助.谢谢!:)

Any help is much appreciated. Thanks!:)

推荐答案

基本答案不是-尝试实现自己的安全代码通常是一个坏主意;有很多选择可以为您节省很多时间,也可以为您节省很多麻烦.

The basic answer is don't - it's generally a bad idea to try to implement your own security code; there's lots of options out there that will save you a lot of time up front, and save you a lot of headaches on the back side, too.

另一个答案是您不能-它内置在新框架中

The other answer is that you can't - it's built in to the new framework from the beginning.

这是用户POCO模型的用途.身份框架以这种方式运行(我想从一开始就认为),并且它反映了OAuth和大多数其他身份验证/授权系统.这是一个非常灵活和高效的模型.

This is what a User POCO model is for. The Identity framework has operated this way (I think since the beginning), and it mirrors OAuth and most other authentication/authorization systems. It's an incredibly flexible and efficient model.

相反,我建议您做的是构建自己的ClaimTypes并使用

Instead what I would recommend doing is build your own ClaimTypes and use those in addition to the ones built in to the framework. Depending on how you're authenticating the user, you should be able to add them when you would create the IPrincipal, anyway.

这篇关于Asp.Net 5(Mvc 6)中的Custom ClaimsPrincipal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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