如何从我的simplemembership的形象和ID [英] how to get the image and ID from my simplemembership

查看:99
本文介绍了如何从我的simplemembership的形象和ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个表simpemembership

i am using this table for simpemembership

[Table("UserProfile")]
    public class UserProfile
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int UserId { get; set; }
        public string UserName { get; set; }
        public int ID { get; set; }
        public byte[] Image { get; set; }
    }

它的工作原理完美的,我做我的CONFIGRATION和迁移以及创建用户和帐户和登录,一切都非常完美,

It works perfect, i made my configration and migration and creating users and accounts and login and everything is perfect,

现在用户登录到我的系统,我让这个

now a user login to my system , i make this

WebSecurity.Login(username, encryptedPassword, false);

它的工作原理。

我想使用的用户informatoin在我的意见。

i want to use the users informatoin in my views.

例如,我有这样的 Request.isAuthenticated 来知道,如果用户进行身份验证或没有。而且我想用自己的ID和图像的(remeber该表中有这些informatoin)

For example, i make this Request.isAuthenticated to know if the user is authenticated or not. but also i want to use his ID and IMage (remeber that table has these informatoin)

如何使用它们吗?7

在其他的世界:​​

我想使用 User.Identity。,但我可以看到名称 ,,我不能看到id和图片

i want to use User.Identity. but i can just see the name,, i can't see the id and the image

在我心中的顶部,我认为,如果这是不可能的,它是一个很好的考虑到存储在cookie中的形象和id?感谢ü

at the top of my mind, i think that if this is not possible, is it a good think to store the image and id in the cookie?thank u

推荐答案

看看这个的在自定义SimpleMembership 文章。它展示了如何获取当前用户的用户配置的对象。下面的例子说明如何抢的用户配置的对象,并访问已添加的邮件属性的例子。

Check out this article on customizing SimpleMembership. It shows how to get the UserProfile object for the current user. Here is an example that shows how to grab the UserProfile object and access an email property that was added.

var context = new UsersContext();
var username = User.Identity.Name;
var user = context.UserProfiles.SingleOrDefault(u => u.UserName == username);
var email = user.Email;

另一种方法是使用href=\"https://simplesecurity.$c$cplex.com/\" rel=\"nofollow\">开源项目SimpleSecurity 的 WebSecurity 的类有一个方法的类的 WebSecurity.GetUser 的是采用用户名作为参数,并返回相关的用户配置的有吧。

Another alternative is to use the open source project SimpleSecurity, which decouples SimpleMembership from your ASP.NET application and extends functionality such as email confirmation and password reset. There is a class that extends the WebSecurity class and has a method WebSecurity.GetUser that takes the username as a parameter and returns the UserProfile associated with it.

这篇关于如何从我的simplemembership的形象和ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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