繁体   English   中英

如何在MVC控制器之外通过SimpleMembership将用户添加到数据库中?

[英]How can I add a user to my database with SimpleMembership outside of the MVC Controller?

我的帐户控制器中有以下代码:

WebSecurity.CreateAccount(User.Identity.Name, model.NewPassword);

这行得通,当我用WebSecurity换行时,我看到intellisense为我提供了我期望的所有选项。

我在另一个类中添加了相同的代码,但是这次我没有使用WebSecurity的选项。 该类显示出来,但是没有可以使用的方法。

有谁知道什么可能是错的。 如何在控制器外部添加用户以播种数据库。

这是我在做什么:

WebSecurity.CreateAccount("xx", "xx", true)

这是错误消息:

Error   2   'WebMatrix.WebData.WebSecurity.CreateAccount(string, string, bool)' is a 'method' but is used like a 'type'

您尚未提供所需的详细信息,但我想您已有此行

WebSecurity.CreateAccount("xx", "xx", true)

没有方法。 像这样(这将导致您描述的错误):

class AccountsController
{
   WebSecurity.CreateAccount("xx", "xx", true);
}

检查您的语法。 如果这行不通,请在错误行附近发布更多代码。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM