FormsAuthentication和WebSecurity之间的区别

16

我正在探索在Visual Studio示例Web应用程序中使用ASP.NET MVC的可能性。WebMatrix.WebData.WebSecurity用于成员身份验证(创建帐户,并指定已登录用户查看特定页面等)。但经过一些搜索,我发现还有System.Web.Security.FormsAuthentication类可用于成员身份验证。

有人知道这两个类之间的区别/优缺点吗?什么时候使用WebSecurity和什么时候使用FormsAuthentication?(以及FormsAuthentication的清晰示例)

谢谢!


2
这里有一篇Jon Galloway的博客文章,可能有助于澄清在两者之间做出决定时的一些好处和权衡利弊:http://weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal-providers-and-the-new-asp-net-4-5-web-forms-and-asp-net-mvc-4-templates.aspx - Jive Boogie
2个回答

16

WebSecurity 是在 WebMatrix 2 和 ASP.NET MVC 4 中引入的。它依赖于 SimpleMembershipProvider。在底层,它使用 FormsAuthentication 来管理 cookie。如果这个模型符合你的需求,我猜你会选择这个新模型来开始一个新项目。请注意,SimpleMembershipProvider 暴露的功能比原始提供程序少。

原始成员资格提供程序使用 SqlMembershipProvider,而 SqlMembershipProvider 又使用普通的 ADO.NET 来查询数据库。

SimpleMembershipProvider 使用在 WebMatrix 中引入的新的 Database 类来查询 SQL 数据库。


1
那么对于一个新的ASP.NET MVC 4应用程序来说,使用哪个并不重要? - mrtentje
3
不,这并不重要。Internet Application Template 默认使用 WebSecurity。但就我个人而言,我从零开始创建一个空的应用程序,使用我想要的任何东西,而不使用任何模板。 - Darin Dimitrov
这将取决于我开始的项目和具体要求。对于这个问题,没有通用的答案。 - Darin Dimitrov
(抱歉好奇)您可以举个例子让我思考一下,比如哪些要求?(WebSecurity与FormAuthentication的优缺点)(对于这个会员/授权问题,我真的不知道如何根据要求做出决策)谢谢! - mrtentje
WebMatrix.WebData.WebSecurity是SimpleMembershipProvider的门面,使用FormsAuthentication。WebSecurity源代码:http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/854bcdb520dc#src/WebMatrix.WebData/WebSecurity.cs - Aaron Hoffman
显示剩余2条评论

8

伙计,你分享的链接太棒了,它为初学者提供了一切所需,我建议大家阅读这个参考链接。再次感谢@Sergey。 - Malik Khalil

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接