ASP.NET成员资格和角色提供程序配置问题

时间:2012-04-20 18:58:41

标签: c# asp.net web-config membership-provider roleprovider

我在尝试启动应用程序时收到错误,并且我认为我的web.config文件中存在错误(请参阅下文)。我已将MembershipProvider架构与现有的RESTAURANT DB结合使用。

我有2个连接字符串,一个是LINQ to Entities,我用它来填充我的应用程序的餐馆数据,另一个是SQL Server 2008 R2连接,用于成员资格和角色提供者。

我收到的错误是在开头的行:role manager =“true”

这是我的Web.Config

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <appSettings></appSettings>
    <connectionStrings>
        <add name="RestaurantDB" 
             connectionString="data source=SFP\SFP_SQL_SVR;attachdbfilename=C:\Users\Susan\Documents\Databases\Restaurants.mdf;Initial Catalog=Restaurants.mdf;Integrated Security=SSPI;"/>
        <add name="RestaurantsEntities" 
             connectionString="metadata=res://*/Restaurant.csdl|res://*/Restaurant.ssdl|res://*/Restaurant.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SFP\SFP_SQL_SVR;attachdbfilename=C:\Users\Susan\Documents\Databases\Restaurants.mdf;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" 
             providerName="System.Data.EntityClient" />
    </connectionStrings>
    <roleManager enabled="true"
                 defaultProvider="CustomizedRoleProvider">
       <providers>
          <add name="CustomizedRoleProvider"
               type="System.Web.Security.SqlRoleProvider"
               connectionStringName="RestaurantsDB" />
       </providers>
    </roleManager>
    <membership defaultProvider="CustomizedMembershipProvider">
       <providers>
          <add name="CustomizedMembershipProvider"
               type="System.Web.Security.SqlMembershipProvider"
               connectionStringName="RestaurantsDB" />
       </providers>
    </membership>
</configuration>

2 个答案:

答案 0 :(得分:3)

您正在指定

<add name="RestaurantDB"

错误

     connectionStringName="RestaurantsDB" />

正确

     connectionStringName="RestaurantDB" />  

如果这个解决了,那就为我祈祷

答案 1 :(得分:3)

<roleManager><membership><system.web>

的孩子

试试这个:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <appSettings>

  </appSettings>

  <connectionStrings>
    <add name="RestaurantDB" connectionString="data source=SFP\SFP_SQL_SVR;attachdbfilename=C:\Users\Susan\Documents\Databases\Restaurants.mdf;Initial Catalog=Restaurants.mdf;Integrated Security=SSPI;"/>
    <add name="RestaurantsEntities" connectionString="metadata=res://*/Restaurant.csdl|res://*/Restaurant.ssdl|res://*/Restaurant.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SFP\SFP_SQL_SVR;attachdbfilename=C:\Users\Susan\Documents\Databases\Restaurants.mdf;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

  <system.web>
      <compilation debug="true" targetFramework="4.0" />

      <roleManager enabled="true"
           defaultProvider="CustomizedRoleProvider">
          <providers>
              <add name="CustomizedRoleProvider"
                  type="System.Web.Security.SqlRoleProvider"
                  connectionStringName="RestaurantsDB" />
          </providers>
      </roleManager>

      <membership defaultProvider="CustomizedMembershipProvider">
           <providers>
               <add name="CustomizedMembershipProvider"
                   type="System.Web.Security.SqlMembershipProvider"
                   connectionStringName="RestaurantsDB" />
           </providers>
      </membership>
  </system.web>
</configuration>

请参阅:http://msdn.microsoft.com/en-us/library/ms228147.aspx

请参阅:http://msdn.microsoft.com/en-us/library/dayb112d.aspx