简体   繁体   English

MVC 2中的配置文件和/或自定义用户注册

[英]Profiles in MVC 2 and/or custom user registration

I am working on an MVC 2 application where I need users to add custom fields when they register, for example age, phone number, full name, etc. 我正在使用MVC 2应用程序,需要用户在注册时添加自定义字段,例如年龄,电话号码,全名等。

Investigating I found this blog entry where they use ASP.NET Profiles and customize the CreateUserWizard control. 调查中,我发现此博客条目使用ASP.NET配置文件并自定义CreateUserWizard控件。 My problem has been that I cannot get this to work since in MVC I have no code-behind and if I had it, probably it wouldn't work since CreateUserWizard uses ViewState . 我的问题是我无法使用它,因为在MVC中我没有任何代码隐藏,如果我有它, 则可能无法使用,因为CreateUserWizard使用ViewState

All I need is what I have said: Ask users to add custom fields when they register (I have already managed to configure Membership, it works well). 我所需要的就是我所说的:要求用户在注册时添加自定义字段(我已经设法配置了成员身份,效果很好)。

I would like to know if there is a way as simple as the one I found to accomplish what I need, whether it uses Profiles or not. 我想知道是否有一种方法像我发现的那样简单,可以完成我所需要的,无论它是否使用Profiles。

I hope you can help me, 我希望你能帮帮我,

Sam 山姆

I found that the easiest way is to use MembershipSystem, but to stay away from ProfileSystem as much as possible. 我发现最简单的方法是使用MembershipSystem,但要尽可能远离ProfileSystem。

I use a Usertable that has a column UserID that maps to UniqueID of ProileSystem. 我使用的Usertable的用户ID列映射到ProileSystem的UniqueID。 You see there is a break in the systems: On the one side there is the profile and on the other side there is my user. 您会看到系统出现了问题:一方面是配置文件,另一方面是我的用户。

This gets a problem here and there: 这到处都是问题:

  • You create the membership user and profile entry and after it you create the entry in the user table. 您创建成员资格用户和概要文件条目,然后在用户表中创建条目。 There is no chance to have a transaction that spans both operations. 没有机会进行跨两个操作的事务。
  • The user changes his E-Mail. 用户更改他的电子邮件。 This has to be done for the Mebrshipsystem and for the table user 必须针对Mebrship系统和表用户执行此操作

You could start implementing properties by a custom ProfileProvider. 您可以开始通过自定义ProfileProvider来实现属性。 This is easy and you can even use your own User table. 这很容易,您甚至可以使用自己的User表。 But in my case I found out that this was bad: To much of the ProfileSystem creeped into my application. 但是在我的情况下,我发现这很不好:许多ProfileSystem都潜入了我的应用程序。 I started by the user table, then I had to think about the address table, the order table.... 我从用户表开始,然后我不得不考虑地址表,订单表...。

At the end I saw that there will be a break somewhere, so decided to have it early. 最后,我看到某个地方会有休息,所以决定早点休息。 Your situation might be different and the ProfileSystem might be helpfull in some situations, but if you start to implement to much of your application inside of the custom profile provider I would think again. 您的情况可能有所不同,在某些情况下ProfileSystem可能会有所帮助,但是如果您开始在自定义配置文件提供程序内部实现大部分应用程序,我会再考虑。

So my suggestion is: 所以我的建议是:

Use MembershipSsytem and ProfileSystem to create an Account and to retrieve an ID for the user. 使用MembershipSsytem和ProfileSystem创建一个帐户并检索该用户的ID。 Then Use this ID in your own Backend. 然后在您自己的后端中使用此ID。

Check out this question; 看看这个问题; maybe this will point you to the right track. 也许这将为您指明正确的方向。 :) :)

Profile question 个人资料问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM