i am new to asp.net mvc so please be explicit as possible.
我是asp.net mvc的新手,所以请尽可能明确。
Here is my goal:
这是我的目标:
i want to create a simple website where users can:
我想创建一个简单的网站,用户可以:
- Register and log in
- Enter there contact details(phone, address, etc)
- View there contact details
- Edit details of #3.
注册并登录
输入联系方式(电话,地址等)
查看联系方式
编辑#3的详细信息。
Later in the website, i will create other pages that use this data but for now the only items above are needed.
稍后在网站上,我将创建使用此数据的其他页面,但现在只需要上面的项目。
my questions is that i have been reviewing the default asp.net mvc sample that comes when you create a new asp.net mvc app.
我的问题是,我一直在审查创建新的asp.net mvc应用程序时出现的默认asp.net mvc示例。
I am trying to figure out if i should store all the contact details in the aspnetdb.mdf database in an existing table or i should be creating new tables.
我试图弄清楚我是否应该将aspnetdb.mdf数据库中的所有联系人详细信息存储在现有表中,或者我应该创建新表。
it seems like i could extend aspnet_Users or aspnet_membership.
好像我可以扩展aspnet_Users或aspnet_membership。
please let me know if these tables can be extended to store additional fields or if its safer to just create a new table in this database.
如果这些表可以扩展到存储其他字段,或者更安全,只需在此数据库中创建一个新表,请告诉我。
3 个解决方案
#1
You could use an Asp.net profile provider to store the information. Follow the link for instructions on using the built-in SqlProfileProvider. By default, the SqlProfileProvider will create tables in the aspnetdb.mdf file, so you can keep everything in one place. You can access the profile provider as a property on the HttpContext.
您可以使用Asp.net配置文件提供程序来存储信息。请按照链接获取有关使用内置SqlProfileProvider的说明。默认情况下,SqlProfileProvider将在aspnetdb.mdf文件中创建表,因此您可以将所有内容保存在一个位置。您可以在HttpContext上作为属性访问配置文件提供程序。
Edit: Better link for ASP.Net profile information
编辑:更好的ASP.Net个人资料信息链接
Using the Profile provider, you don't have to worry about making database calls or identifying the current user. It's all done on your behalf. Double-check the documentation, because the following might be a little off.
使用配置文件提供程序,您不必担心进行数据库调用或识别当前用户。这一切都是代表你完成的。仔细检查文档,因为以下内容可能有点偏差。
You add the fields that you want in your web.config inside <system.web>
. In your case, it would be the necessary contact information.
您可以在
<profile>
<properties>
<add name="Address" />
<add name="City" />
<add name="State" />
<plus other fields ... />
</properties>
</profile>
Then, you can access HttpContext.Profile.Address and so forth and the provider will take care of tying everything to the current user.
然后,您可以访问HttpContext.Profile.Address等等,提供程序将负责将所有内容绑定到当前用户。
Adding and editing the information means displaying a form. Viewing the details is just displaying all the fields you saved from the previous form post.
添加和编辑信息意味着显示表单。查看详细信息只显示您从上一个表单发布中保存的所有字段。
The NerdDinner source and tutorial are well worth checking out if you're completely new to MVC.
如果你是MVC的新手,那么NerdDinner的源代码和教程非常值得一试。
#2
You may also want to take a look at the SQL Server Publishing Wizard found here.
您可能还想查看此处的SQL Server发布向导。
It essentially allows you to copy the database structure and/or data to a .sql file that you can then import into your primary SQL database.
它本质上允许您将数据库结构和/或数据复制到.sql文件,然后可以将其导入主SQL数据库。
I don't particularly like the aspnetdb approach but that's my personal opinion.
我不是特别喜欢aspnetdb方法,但那是我个人的看法。
#3
This question has been the cause of a little bit of an internal debate for me. I can see the logic in extending the existing membership provider to hold the neccessary aditional information, however I would only use the aspnetdb database to store this information if that was the path taken, as the purpose of that database, in my mind, is to store information mamaged by ASP.NET via the Membership API
这个问题一直是我内部辩论的一个原因。我可以看到扩展现有成员资格提供程序以保存必要的附加信息的逻辑,但是如果这是所采用的路径,我只会使用aspnetdb数据库存储此信息,因为在我看来,该数据库的目的是存储由ASP.NET通过Membership API进行mamaged信息
If you did decide not to extend asp.net's existing membership provider then I would suggest creating another database, or at the very least some new table(s) to keep data you are managing seperate from any other data managed by ASP.NET
如果您确实决定不扩展asp.net的现有成员资格提供程序,那么我建议创建另一个数据库,或者至少创建一些新表来保持您管理的数据与ASP.NET管理的任何其他数据分开。
#1
You could use an Asp.net profile provider to store the information. Follow the link for instructions on using the built-in SqlProfileProvider. By default, the SqlProfileProvider will create tables in the aspnetdb.mdf file, so you can keep everything in one place. You can access the profile provider as a property on the HttpContext.
您可以使用Asp.net配置文件提供程序来存储信息。请按照链接获取有关使用内置SqlProfileProvider的说明。默认情况下,SqlProfileProvider将在aspnetdb.mdf文件中创建表,因此您可以将所有内容保存在一个位置。您可以在HttpContext上作为属性访问配置文件提供程序。
Edit: Better link for ASP.Net profile information
编辑:更好的ASP.Net个人资料信息链接
Using the Profile provider, you don't have to worry about making database calls or identifying the current user. It's all done on your behalf. Double-check the documentation, because the following might be a little off.
使用配置文件提供程序,您不必担心进行数据库调用或识别当前用户。这一切都是代表你完成的。仔细检查文档,因为以下内容可能有点偏差。
You add the fields that you want in your web.config inside <system.web>
. In your case, it would be the necessary contact information.
您可以在
<profile>
<properties>
<add name="Address" />
<add name="City" />
<add name="State" />
<plus other fields ... />
</properties>
</profile>
Then, you can access HttpContext.Profile.Address and so forth and the provider will take care of tying everything to the current user.
然后,您可以访问HttpContext.Profile.Address等等,提供程序将负责将所有内容绑定到当前用户。
Adding and editing the information means displaying a form. Viewing the details is just displaying all the fields you saved from the previous form post.
添加和编辑信息意味着显示表单。查看详细信息只显示您从上一个表单发布中保存的所有字段。
The NerdDinner source and tutorial are well worth checking out if you're completely new to MVC.
如果你是MVC的新手,那么NerdDinner的源代码和教程非常值得一试。
#2
You may also want to take a look at the SQL Server Publishing Wizard found here.
您可能还想查看此处的SQL Server发布向导。
It essentially allows you to copy the database structure and/or data to a .sql file that you can then import into your primary SQL database.
它本质上允许您将数据库结构和/或数据复制到.sql文件,然后可以将其导入主SQL数据库。
I don't particularly like the aspnetdb approach but that's my personal opinion.
我不是特别喜欢aspnetdb方法,但那是我个人的看法。
#3
This question has been the cause of a little bit of an internal debate for me. I can see the logic in extending the existing membership provider to hold the neccessary aditional information, however I would only use the aspnetdb database to store this information if that was the path taken, as the purpose of that database, in my mind, is to store information mamaged by ASP.NET via the Membership API
这个问题一直是我内部辩论的一个原因。我可以看到扩展现有成员资格提供程序以保存必要的附加信息的逻辑,但是如果这是所采用的路径,我只会使用aspnetdb数据库存储此信息,因为在我看来,该数据库的目的是存储由ASP.NET通过Membership API进行mamaged信息
If you did decide not to extend asp.net's existing membership provider then I would suggest creating another database, or at the very least some new table(s) to keep data you are managing seperate from any other data managed by ASP.NET
如果您确实决定不扩展asp.net的现有成员资格提供程序,那么我建议创建另一个数据库,或者至少创建一些新表来保持您管理的数据与ASP.NET管理的任何其他数据分开。