如何解决此错误' connectionStringName'在MVC 4中的asp.net的web.config中不允许使用该属性

时间:2017-10-19 15:47:11

标签: c# asp.net asp.net-mvc visual-studio visual-studio-2012

如何解决connectionStringName'的问题? mvc 4 asp.net中的visual studio中不允许使用该属性

web.config

错误图片在这里enter image description here

<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-MVE-20171019175539;Integrated Security=SSPI" />
<add name="SchoolContext"    connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\university.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

Web.config // Line 60 column 189 the code below

    <providers>
    <add name="DefaultSessionProvider" 
    type="System.Web.Providers.DefaultSessionStateProvider, 
    System.Web.Providers, Version=1.0.0.0, Culture=neutral, 
    PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
    </providers>

1 个答案:

答案 0 :(得分:0)

卸下:

<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-MVE-20171019175539;Integrated Security=SSPI" />

来自您的连接字符串。您不需要它,因为您正在使用&#39; SchoolContext&#39;。

删除:

<providers>
<add name="DefaultSessionProvider" 
type="System.Web.Providers.DefaultSessionStateProvider, 
System.Web.Providers, Version=1.0.0.0, Culture=neutral, 
PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
</providers>

你没有使用任何形式的身份验证吗?