SimpleMembership MVC4(现有数据库) [英] SimpleMembership MVC4 (existing database)

查看:119
本文介绍了SimpleMembership MVC4(现有数据库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正与一个MVC4应用程序和数据库工作。我想使用默认的登录和注册程序/方法。

At the moment I am working with a MVC4 application and a database. I want to use the default login and register procedure/ methods.

我使用一个表的用户信息,如,名字,姓氏,密码,电子邮件......

I am using a table with user information like, firstname, surname, password, email...

我只是想用我的数据库默认注册/登录方法。
在互联网上我看了几个主题,但他们都不给我一个正确的答案。

I just want to use my database with the default register/ login methods. On the internet I read several topics, but none of them give me a correct answer.

这是我已经做的:

1使用SimpleMembership

1 Use SimpleMembership

于是我又说:

<add key="enableSimpleMembership" value="true">

2添加字段到RegisterModel

2 Added fields to the RegisterModel

3更改CreateUserAndAccount参数太多:

3 Change the CreateUserAndAccount parameters too:

WebSecurity.CreateUserAndAccount(model.Email, model.Password, new {FirstName = model.UserName, SurName = model.UserName}, false);

这是解决这个问题还是有其他解决方案的最佳方式是什么?

Is this the best way to solve this problem or are there other solutions?

感谢你在前进!

推荐答案

<一个href=\"http://msdn.microsoft.com/en-us/library/webmatrix.webdata.websecurity.createuserandaccount%28v=vs.111%29.aspx\"相对=nofollow> WebSecurity.CreateUserAndAcccount 让你定制你如何填充的用户配置的实体的属性,但你必须更新的用户配置的类它的工作外的开箱。你可以阅读更多有关定制SimpleMembership这里。的用户配置的是,如果你只使用由Internet模板在您创建MVC 4项目生成的内容所使用的默认的实体/表。要使用其他的表,你将需要改变的 WebSecurity.InitializeDatabaseConnection 指向现有的表,定义用户ID列和用户名列。用户ID必须是整数,以便它可以与用于通过SimpleMembership存储哈希密码进行认证所需要的其他信息的webpages_Membership表被接合

WebSecurity.CreateUserAndAcccount allows you to tailor how you populate the properties of the UserProfile entity, but you have to update the UserProfile class for it to work out-of-the-box. You can read more about customizing SimpleMembership here. UserProfile is the default entity/table that is used if you just use what was generated by the Internet Template when you created your MVC 4 project. To use another table you will need to change the parameters in WebSecurity.InitializeDatabaseConnection to point to your existing table and define what the user ID column is and the user name column is. The user ID must be an integer so that it can be joined with the webpages_Membership table used by SimpleMembership to store the hashed password an other information required for authentication.

由互联网模板生成的code使用与初始化数据库的延迟加载方法的 InitializeSimpleMembershipAttribute 的,你会在你的项目的过滤器文件夹中找到。这是的 InitializeDatabaseConnection的被称为哪里。它也可以实现这样的情况下,开发商没有使用窗体身份验证和应用程序仍然可以工作。如果您在使用窗体身份验证我preFER更这里描述数据库初始化的直线前进的方法。

The code generated by the Internet Template uses a lazy loading method of initializing the database with the InitializeSimpleMembershipAttribute, which you will find in the Filters folder of your project. This is where the InitializeDatabaseConnection is called. It is also implemented this way in case the developer does not use forms authentication and the application will still work. If you are using forms authentication I prefer the more straight forward method of database initialization described here.

有与这取决于你的应用需求SimpleMembership,我会给你短短很多选择。 1)自定义的用户配置的有你在你现有的数据库,如果您有任何现有数据迁移过来的属性。 2)修改的 InitializeDatabaseConnection 的和的 CreateUserAndAccount 的与您现有的表工作。 3)添加一个外键的用户配置的,让你在SimpleMembership用户加入到现有的表。

There are many options with SimpleMembership depending upon your application requirements and I will give you just a few. 1) customize the UserProfile to have the properties you have in your existing database and if you have any existing data migrate it over. 2) Modify InitializeDatabaseConnection and CreateUserAndAccount to work with your existing table. 3) Add a foreign key to UserProfile that will allow you to join a user in SimpleMembership to your existing table.

这篇关于SimpleMembership MVC4(现有数据库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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