asp.net HTTP错误500.19 -内部服务器错误无法访问请求的页面,因为该页面的相关配置数据无效

sr4lhrrt  于 2022-12-24  发布在  .NET
关注(0)|答案(1)|浏览(107)

我一直在尝试将我的ASP.NET Web应用程序(.NET框架)连接到我的本地SQL数据库,但我一直收到相同的错误,其中显示“配置节'connectionStrings'无法读取,因为它缺少节声明”,如下图所示。
这是我的web.config代码。

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
      <connectionStrings>
          <add name = "Milestone3"
             connectionstring = "Data Source = (localdb)\MSSQLLocalDB;Initial Catalog=Milestone_2;Integrated Security=True"/>
      </connectionStrings>
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2" />
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
</configuration>

我在其他堆栈溢出问题上看到有人删除了.vs文件夹并重建了项目,但它仍然不起作用。我也尝试了,但没有任何React
1.打开控制面板
1.点击“程序”链接(不卸载程序)
1.单击“打开/关闭Windows功能”链接
1.在弹出窗口中找到“Internet信息服务IIS”并展开其节点
1.展开“万维网服务”节点
1.展开“应用程序开发功能”节点
1.勾选“ASP.NET”复选框
1.然后单击确定按钮

kq4fsx7k

kq4fsx7k1#

<connectionStrings>节点应该是<configuration>的子节点,而不是<system.web>的子节点。请将其更改为:

<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <connectionStrings>
    <add name = "Milestone3" connectionstring = "Data Source = (localdb)\MSSQLLocalDB;Initial Catalog=Milestone_2;Integrated Security=True"/>
  </connectionStrings>
  <system.web>         
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2" />
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
</configuration>

相关问题