为SimpleMembership配置MVC [英] Configuring MVC for SimpleMembership

查看:64
本文介绍了为SimpleMembership配置MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET MVC应用程序,其中包含许多从项目模板生成的与成员资格相关的页面。

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:


无法初始化ASP.NET简单成员资格数据库。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkId=256588

经过一段时间的研究,我确定我错过了连接字符串。我有一个名为 FreeWebFilesEntities 的现有连接字符串,并创建了一个名为 DefaultConnection 的新连接字符串,并为其指定了相同的值。

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>

但它仍然不喜欢这样。我找到了一些资源,提示我正在使用EF连接字符串(现在是)。我尝试删除它的元数据部分,但是无论我做什么,都会引发异常。

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.

由于Microsoft似乎决定不非常仔细地记录此过程(如果完全没有),有人知道吗?如何使SimpleMembership页面正常工作?

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?

推荐答案

嗯,对于初学者来说,您使用的是 EntityClient 连接字符串,与 SimpleMembership 不兼容。 SimpleMembership 需要 SqlClient 提供程序类型的连接字符串(即,它没有元数据并且提供程序类型为 SqlClient

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)

第二,使用的连接字符串在您的 InitializeSimpleMembershipAttribute.cs <中设置/ code>类,尤其是调用 WebSecurity.InitializeDatabaseConnection 的行。您可以将其更改为任何您想要的。 DefaultConnection是machine.config中提供的默认连接字符串,默认情况下不会显示在web.config中。

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.

这篇关于为SimpleMembership配置MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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