【问题标题】:Difference between FormsAuthentication and WebSecurityFormsAuthentication 和 WebSecurity 之间的区别
【发布时间】:2012-10-01 18:40:01
【问题描述】:

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

有人知道这两个课程之间的区别/优点和缺点吗?以及何时使用 WebSecurity 以及何时使用 FormsAuthentication? (也许是 FormsAuthentication 的一个明显例子)

提前致谢

【问题讨论】:

标签: c# asp.net-mvc asp.net-membership


【解决方案1】:

WebSecurity 是在 WebMatrix 2 和 ASP.NET MVC 4 中引入的。它依赖于SimpleMembershipProvider。在幕后,它使用FormsAuthentication 来管理cookies。所以我想如果你开始一个新项目,如果这个模型符合你的需要,你会选择新模型。请记住,SimpleMembershipProvider 公开的功能少于原始提供程序。

最初的成员​​资格提供程序使用 SqlMembershipProvider,而后者又使用普通的 ADO.NET 来查询数据库。

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

【讨论】:

  • 那么对于一个新的 ASP.NET MVC 4 应用程序来说,使用哪一个并不重要?
  • 不,这并不重要。 Internet 应用程序模板默认使用 WebSecurity。但就我个人而言,我从不使用任何模板。我从头开始创建一个空应用程序,在其中使用我想使用的任何内容。
  • 感谢您的快速回答! (只是想知道)当你从头开始时,你更喜欢什么?您使用其中之一(WebSecurity 或 FormsAuthentication)还是创建自己的库或其他库?
  • 这将取决于我开始的项目和具体要求。这个问题没有一般的答案。
  • (抱歉好奇) 但是你能举一个(小)例子,让我想想哪些要求? (WebSecurity 与 FormAuthentication 的优缺点)(我真的不知道如何根据这个会员/授权问题的要求做出决定)提前致谢!
【解决方案2】:

旧的 ASP.NET Membership 提供程序和 SimpleMembershipProvider 之间的主要区别在这篇好文章 - 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 中进行了解释

使用 SimpleMembershipProvider (WebMatrix.WebData.WebSecurity) 比旧的 ASP.NET Membership Provider(或 Universal Providers)更好

【讨论】:

  • 你分享的链接太棒了,初学者可以从它开始。我建议所有人阅读这个参考链接。再次感谢@Sergey
猜你喜欢
  • 2012-08-17
  • 2016-01-10
  • 1970-01-01
  • 2021-12-25
  • 2020-05-10
  • 2014-09-20
  • 2010-10-28
  • 2015-10-04
  • 2012-08-12
相关资源
最近更新 更多