Asp.net mvc 4 _AppStart.cshtml、PackageManager、WebMatrix

Asp.net mvc 4 _AppStart.cshtml、PackageManager、WebMatrix,asp.net-mvc-4,Asp.net Mvc 4,我认为将SimpleMemberSip添加到MVC4 web是一件简单的事情。不是这样。模板化代码(例如C#)非常适合支持它,但web.config基本上是不可知的——没有配置任何特定安全机制的元素。我一直在关注Scott Allen关于Pluralsight的MVC4教程,该教程将aspnet成员资格与EF内容混合在一起。也许我错过了一些东西,但是C#会员类并没有与aspnet会员进行交互,他们只是在做简单的会员身份。所以,我删除了aspnet成员资格,但现在我无法让PackageManage

我认为将SimpleMemberSip添加到MVC4 web是一件简单的事情。不是这样。模板化代码(例如C#)非常适合支持它,但web.config基本上是不可知的——没有配置任何特定安全机制的元素。我一直在关注Scott Allen关于Pluralsight的MVC4教程,该教程将aspnet成员资格与EF内容混合在一起。也许我错过了一些东西,但是C#会员类并没有与aspnet会员进行交互,他们只是在做简单的会员身份。所以,我删除了aspnet成员资格,但现在我无法让PackageManager“更新数据库”。它抱怨“您必须调用WebSecurity.InitializeDatabaseConnection方法…”。因此,我在调用中添加了一个_AppStart.cshtml文件,但PM似乎不知道。 _AppStart.cshtml:

@using WebMatrix.WebData;
@{
    WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", true);
}
Web.config:

  <appSettings>
    <add key="enableSimpleMembership" value="true" />
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>

   <roleManager enabled="true" defaultProvider="simple">
     <providers>
        <clear/>
        <add name="simple" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" />
      </providers>
    </roleManager>


    <membership defaultProvider="simple">
      <providers>
        <clear/>
        <add name="simple" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
      </providers>
    </membership
未创建角色“Admin”。?

请尝试添加代码

WebSecurity.InitializeDatabaseConnection(“DefaultConnection”、“UserProfile”、“UserId”、“UserName”、true)

到您的应用程序\u从
global.asax.cs


\u appStart.cshtml
未在MVC中使用。

在MVC4中可能使用\u appStart.cshtml 通过创建新文件并将其放入根文件夹

@{
 // Initialize WebMail helper
 WebMail.SmtpServer = "your-SMTP-host";
 WebMail.SmtpPort = 25;
 WebMail.UserName = "your-user-name-here";
 WebMail.Password = "your-account-password";
 WebMail.From = "your-email-address-here";
 }

请概括您的代码示例,并指出您的实际问题所在。在项目树中,文件是在哪里添加的?我将它添加到web应用程序的根目录中,它对我起了作用。当做
@{
 // Initialize WebMail helper
 WebMail.SmtpServer = "your-SMTP-host";
 WebMail.SmtpPort = 25;
 WebMail.UserName = "your-user-name-here";
 WebMail.Password = "your-account-password";
 WebMail.From = "your-email-address-here";
 }