MVC5空白项目的成员
Membership in MVC5 blank project
我正在尝试让成员资格在 asp.net mvc5 空白项目中工作。我正在为此使用 db first 方法并为此安装了 apsnet_regsql
。在我创建了 vs2012 互联网应用程序并从模型、过滤器、控制器和视图中复制了所有内容之后。
但是我遇到了一个问题。当我尝试访问登录(或其他)时,它会抛出异常:
An exception of type 'System.ArgumentException' occurred in
System.Data.dll but was not handled in user code
Additional information: Unable to find the requested .Net Framework
Data Provider. It may not be installed.
这是我的连接字符串:
<add name="CSharpAssignmentDbContext" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="data source=GIORGI\SQLEXPRESS;initial catalog=CSharpAssignmentDb;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
起初我遇到了另一个问题,然后我发现 here
Create a file in the root of your web app called _AppStart.cshtml and
put this in it:
@{
if (!WebSecurity.Initialized)
{
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId",
"UserName", autoCreateTables: true);
}
}
有什么问题吗?我首先使用最新的 EF 6.1.3 Db
我发现 here
You cannot use that connectionstring for anything else than the edmx
connection. The way I have it in my web.config makes the website use
that same connectionstring for the membership stuff too, which is not
compatible with the System.Data.EntityClient provider and needs the
System.Data.Sqlclient in my case. Adding a second connectionstring,
minus the Entity Framework stuff in it and having that referenced by
the membership provider attributes in the web.config removes all
errors and allows the page to render and request stuff from the SQL
server.
所以我添加了第二个连接字符串
<add name="DefaultConnection" connectionString="Data Source=.\SQLExpress;Initial Catalog=CSharpAssignmentDb;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
它解决了我的问题
我正在尝试让成员资格在 asp.net mvc5 空白项目中工作。我正在为此使用 db first 方法并为此安装了 apsnet_regsql
。在我创建了 vs2012 互联网应用程序并从模型、过滤器、控制器和视图中复制了所有内容之后。
但是我遇到了一个问题。当我尝试访问登录(或其他)时,它会抛出异常:
An exception of type 'System.ArgumentException' occurred in System.Data.dll but was not handled in user code
Additional information: Unable to find the requested .Net Framework Data Provider. It may not be installed.
这是我的连接字符串:
<add name="CSharpAssignmentDbContext" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="data source=GIORGI\SQLEXPRESS;initial catalog=CSharpAssignmentDb;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
起初我遇到了另一个问题,然后我发现 here
Create a file in the root of your web app called _AppStart.cshtml and put this in it:
@{
if (!WebSecurity.Initialized)
{
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId",
"UserName", autoCreateTables: true);
}
}
有什么问题吗?我首先使用最新的 EF 6.1.3 Db
我发现 here
You cannot use that connectionstring for anything else than the edmx connection. The way I have it in my web.config makes the website use that same connectionstring for the membership stuff too, which is not compatible with the System.Data.EntityClient provider and needs the System.Data.Sqlclient in my case. Adding a second connectionstring, minus the Entity Framework stuff in it and having that referenced by the membership provider attributes in the web.config removes all errors and allows the page to render and request stuff from the SQL server.
所以我添加了第二个连接字符串
<add name="DefaultConnection" connectionString="Data Source=.\SQLExpress;Initial Catalog=CSharpAssignmentDb;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
它解决了我的问题