我创建了以下控制器和方法来备份我的数据库:
namespace WebUx.Controllers
{
[Authorize(Roles = "Admin")]
//[InitializeSimpleMembership]
public class BackupController : Controller
{
public ActionResult BackupDatabase()
{
var dbPath = Server.MapPath("~/App_Data/DBBackup.bak");
using (var db = new TestDBContext())
{
var cmd = String.Format("BACKUP DATABASE {0} TO DISK='{1}' WITH FORMAT, MEDIANAME='DbBackups', MEDIADESCRIPTION='Media set for {0} database';"
, "TesteDB", dbPath);
db.Database.ExecuteSqlCommand(cmd);
}
return new FilePathResult(dbPath, "application/octet-stream");
}
}
}
但是,当我尝试运行它时,我收到以下消息:
You must call the "WebSecurity.InitializeDatabaseConnection" method before you call any other method of the "WebSecurity" class. This call should be placed in an _AppStart.cshtml file in the root of your site.
我看到 Stackoverflow 上的一个解决方案是添加:[InitializeSimpleMembership] 我添加了这个,但它告诉它找不到类并要求我生成一个。
有人可以解释这是什么意思吗?