简体   繁体   English

在ASP.NET MVC中管理用户的最佳方法是什么

[英]What is the best way to manage users in ASP.NET MVC

I'm new in ASP.NET MVC. 我是ASP.NET MVC的新手。 I've switched to it from PHP. 我已经从PHP切换到了它。

In PHP, when i was creating a page that manage users, i often created the tables Users and Profiles and store the data in them. 在PHP中,当我创建一个管理用户的页面时,我经常创建表Users和Profiles并将数据存储在其中。 In ASP.NET, there are the Membership and Profile Providers. 在ASP.NET中,有成员资格和配置文件提供程序。

So, my question is, what is the best way to manage users in ASP.NET MVC? 所以,我的问题是,在ASP.NET MVC中管理用户的最佳方法是什么? Should I create custom tables and logic like in PHP or should I create Custom Providers? 我应该像在PHP中创建自定义表和逻辑,还是应该创建自定义提供程序?

I know, there are many similiar topics about this problem. 我知道,关于这个问题有很多类似的话题。 However, none of them is exactly what I need. 但是,它们都不是我所需要的。

Thanks in advance, Mike. 先谢谢你,迈克。

use ASP.Net Memebership do not recreate the wheel, 使用ASP.Net Memebership不重新创建轮子,

http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-7 http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-7

Probably should say there is no best way. 可能应该说没有最好的方法。 Best is ambiguous. 最好是暧昧。

I'd say there are three general types of ways to do users and roles with a SQL server (I mention this because you mentioned tables). 我想说有三种一般类型的方法可以用SQL服务器做用户和角色(我之前提到这是因为你提到了表)。

First: Use the built-in ASP.NET (webforms/mvc agnostic) SqlMembership Provider . 第一:使用内置的ASP.NET(webforms / mvc不可知) SqlMembership Provider It contains most of the features people need to manage users. 它包含了管理用户所需的大多数功能。 This is most likely to be the fastest to implement, but the least extensible. 这很可能是最快的实现,但最不可扩展。 This would be highly recommended. 强烈建议这样做。

Second: Build your own [Membership Provider], to follow the Membership provider pattern but introduce your own logic from the SQL to the Application. 第二:构建自己的[Membership Provider],遵循Membership provider 模式,但是从SQL到Application引入您自己的逻辑。 Building your own provide can be quite a lengthy process, but you still get all the nice features, and can be used in other projects because it is it's own provider and not tied to the application. 构建自己的提供可能是一个相当漫长的过程,但您仍然可以获得所有不错的功能,并且可以在其他项目中使用,因为它是它自己的提供程序而不依赖于应用程序。

Third: Build your own logic from complete scratch. 第三:从头开始构建自己的逻辑。 I would not recommend this unless you plan to build it like an independent application. 除非您打算像独立应用程序一样构建它,否则我不会建议这样做。

I agree with Oscar and frenchie - don't reinvent the wheel. 我同意奥斯卡和狂热 - 不要重新发明轮子。 The ASP.NET membership providers should provide you with a good start. ASP.NET成员资格提供程序应该为您提供一个良好的开端。 However, if you're a fan of TDD, you may find you'll need to encapsulate the membership provider implementation inside a class you can control so that you can deal with mocking. 但是,如果您是TDD的粉丝,您可能会发现您需要将成员资格提供程序实现封装在您可以控制的类中,以便您可以处理模拟。 The membership provider contract is pretty huge and tightly coupled, and I've found out through experience that you end up only using 30-40% of that beast. 会员提供商合同非常庞大且紧密耦合,我通过经验发现,您最终只使用了30-40%的野兽。 Create your own contract and use it to interact with the membership provider. 创建自己的合同并使用它与会员提供商进行交互。 You'll thank yourself later. 你以后会感谢你自己。

Good luck! 祝好运!

暂无
暂无

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

相关问题 在ASP.NET网站的ActiveDirectory中管理角色的最佳方法是什么? - What is the best way to manage roles in ActiveDirectory for ASP.NET Website? 在ASP.NET 2.0中管理设置(配置)的最佳方法是什么? - What is the best way to manage settings (configuration) in ASP.NET 2.0? 在ASP.Net MVC中管理MongoDB连接的正确方法是什么? - What is the right way to manage MongoDB connections in ASP.Net MVC? 在 Asp.Net MVC 中存储 Authorize 属性的用户列表的最佳方法是什么? - What is the best way to store Users list for a Authorize attribute in Asp.Net MVC? 在ASP.NET MVC中设计向导表单的最佳方法是什么 - what is the best way to design a wizard form in ASP.NET MVC 在asp.net MVC中管理String的最佳方法(比较并检查是否存在) - Best Way to manage String inside my asp.net mvc (comparison and check existence) 为ASP.NET MVC Intranet应用程序实施Windows身份验证的最佳方法是什么? - What's the best way to implement Windows Authentication for an ASP.NET MVC intranet application? 在ASP.NET MVC解决方案中从我的域对象重构表示代码的最佳方法是什么? - What is the best way to refactor presentation code out of my domain objects in an ASP.NET MVC solution? ASP.NET MVC - 从视图中创建 Url 到 controller 动作的最佳方法是什么? - ASP.NET MVC - What's the best way to create a Url to controller action from within view? 设置用户输入数据的时间限制的最佳方法是什么? (asp.net mvc) - What is the best way to set time boundries for user to input data? (asp.net mvc)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM