_AppStart.cshtml,软件包管理系统,WebMatrix中 [英] _AppStart.cshtml, PackageManager, WebMatrix

查看:175
本文介绍了_AppStart.cshtml,软件包管理系统,WebMatrix中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我thouht这将是一个简单的事情SimpleMembersihp添加到MVC4网络。事实并非如此。模板化code(例如C#)是非常适合于支持它,但web.config中大多agnostic--缺乏,将配置任何特定的安全机制的元素。我下面就Pluralsight--斯科特·艾伦的MVC4教程与EF东西混合ASPNET-邻人。也许我错过了一些东西,但C#会员类均与ASPNET,会员互动,他们正在做SimpleMembership。所以,我删除ASPNET成员资格,但现在我不能让软件包管理系统,以更新数据库。它抱怨:你必须调用WebSecurity.InitializeDatabaseConnection方法......。所以,我添加了一个调用文件_AppStart.cshtml,但似乎PM不知情。
_AppStart.cshtml:

I thouht it would be a simple thing to add SimpleMembersihp to an MVC4 web. Not so. The templated code (e.g. C#) is well-suited to supporting it, but web.config is mostly agnostic-- devoid of elements that would configure any particular security mechanism. I was following Scott Allen's MVC4 tutorial on Pluralsight-- that mixed aspnet-Membership with EF stuff. Maybe I missed something, but C# membership-classes were not interacting with aspnet-Membership, they were doing SimpleMembership. So, I removed aspnet-Membership, but now I cannot get PackageManager to 'update-database'. It complains "You must call the WebSecurity.InitializeDatabaseConnection method...". So, I added an _AppStart.cshtml file with the call, but PM seems unaware. _AppStart.cshtml:

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

Web.config文件:

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

Configuration.cs:

Configuration.cs:

protected override void Seed(eManager.Web.Infrastructure.DepartmentDb context)
{
    context.Departments.AddOrUpdate(d => d.Name,
      new Department() { Name = "Engineering" },
      new Department() { Name = "Sales" },
      new Department() { Name = "Shipping" },
      new Department() { Name = "Human Resources" }
      );

    SimpleRoleProvider roles = new WebMatrix.WebData.SimpleRoleProvider();
    SimpleMembershipProvider membership = new SimpleMembershipProvider();
    if (!roles.RoleExists("Admin"))
    {
        roles.CreateRole("Admin");
    }

    //if (membership.GetUser("ej", false) == null)
    //{
        //    membership.CreateUserAndAccount("ej", "FluffyBunny@1", false);
        //    string[] u = { "ej" };
        //    string[] r = { "Admin" };
        //    roles.AddUsersToRoles(u, r);
        //}
}

中的作用联系是不是创造?

The role "Admin" is not created.?

推荐答案

尝试添加code

WebSecurity.InitializeDatabaseConnection(DefaultConnection,用户配置,用户ID,用户名,真正的);

要在的global.asax.cs

_appStart.cshtml 不MVC使用。

这篇关于_AppStart.cshtml,软件包管理系统,WebMatrix中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆