好的,所以我一直在努力让这个 SimpleMembership 废话发挥作用。我想要一个 DataAccess 层,并且试图让它执行 SimpleMembership 职责。我想我已经接近了,但现在我的 InitializeDatabaseConnection 找不到我的连接字符串。
这是代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Transactions;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using System.Data.Entity;
using Microsoft.Web.WebPages.OAuth;
using WebMatrix.WebData;
namespace ElectricCrew.DataAccess
{
public class SimpleMembership
{
public static void Register(string UserName, string Password)
{
WebSecurity.InitializeDatabaseConnection("ECEntities", "UserProfile", "UserId", "UserName", autoCreateTables: true);
WebSecurity.CreateUserAndAccount(UserName, Password);
WebSecurity.Login(UserName, Password);
}
}
}
这是来自数据访问层的 App.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="ECEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\DefaultConnection.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
很抱歉格式不好。我的电脑无法正确粘贴。
这是我的数据访问层的样子
请停下来