使用web.config中的凭据设置配置成员资格提供程序

时间:2012-11-08 14:32:59

标签: asp.net-mvc-4 membership-provider

我正在尝试在ASP.NET MVC4应用程序中实现表单身份验证,而我只有一个用户将通过身份验证来执行某些管理活动。

<authentication mode="Forms">
  <forms timeout="2880" loginUrl="~/Admin/Login" slidingExpiration="true">
    <credentials passwordFormat="Clear">
      <user name="user" password="password"/>
    </credentials>
  </forms>
</authentication>

当我尝试使用FormsAuthentication.ValidateUser方法时,我得到一个过时的警告,我应该使用现在的Membership类。

我的问题是如何在web.config中配置成员资格提供程序以使用web.config中的凭据设置?我应该在name属性中指定哪个提供商?

1 个答案:

答案 0 :(得分:2)

不幸的是,正如您所描述的那样,没有内置的成员资格提供程序来存储web.config中的凭据。您可以编写自己的方法来调用FormsAuthentication.Authenticate方法,或者从您自己的自定义登录控件的代码隐藏中调用它。