Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

asp.net mvc - Configuring MVC for SimpleMembership

I have an ASP.NET MVC application with a number of membership-related pages generated from the project templates.

When I attempt to access one of those pages, I get the following error:

The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588.

After some time spent researching, I determined I was missing the connection string. I have an existing connection string named FreeWebFilesEntities and I created a new connection string named DefaultConnection, and gave it the same value.

<connectionStrings>
    <add name="FreeWebFilesEntities" connectionString="metadata=res://*/FreeWebFilesRepository.csdl|res://*/FreeWebFilesRepository.ssdl|res://*/FreeWebFilesRepository.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.;Initial Catalog=FreeWebFiles;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
    <add name="DefaultConnection" connectionString="metadata=res://*/FreeWebFilesRepository.csdl|res://*/FreeWebFilesRepository.ssdl|res://*/FreeWebFilesRepository.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.;Initial Catalog=FreeWebFiles;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
<connectionStrings>

But it still doesn't like this. I found some resources that suggested I'm using an EF connection string (and I am). I tried removing the metadata section of it but, no matter what I do, it throws an exception.

Since it appears Microsoft decided not to document this process very carefully (if at all), has anyone figured this out? How can I get the SimpleMembership pages to work?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Well, for starters, you are using a EntityClient connection string, which is incompatible with SimpleMembership. SimpleMembership requires a SqlClient provider type connection string (ie, it does not have the metadata and the provider type is SqlClient)

Second, the connection string that is used is set in your InitializeSimpleMembershipAttribute.cs class, in particular the line that calls WebSecurity.InitializeDatabaseConnection. You can change this to whatever you want. DefaultConnection is the default connection string supplied in the machine.config, and does not by default show up in your web.config.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...