Visual Studio で ASP.NETのプロジェクトを実行すると 「ページに関する構成データが無効であるため、要求されたページにアクセスできません : Error Code 0x80070003」 エラー、「構成ファイルを読み取れません」エラーが発生する - Visual Studio

Visual Studio で ASP.NETのプロジェクトを実行すると 「ページに関する構成データが無効であるため、要求されたページにアクセスできません」のエラーが発生しページが表示できない状態になる問題の対処法です。

現象

Visual StudioでASP.NETプロジェクトを実行すると以下のエラーが発生します。

エラー事例:1

エラーメッセージ
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
エラーメッセージの詳細
Detailed Error Information:
Module : IIS Web Core
Notification : Unknown
Hendler :  Not yet determined
Error Code 0x80070003
Config Error : 構成ファイルを読み取れません
構成ファイル : \\?\C:\(プロジェクトのフォルダ)\web.config
Requested URL : https://localhost:nnnnn/(アプリケーションのパス)
Physical Path
Logon Method : Not yet determined
Logon User : Not yet determined
追加情報
More Information:
This error occurs when there is a problem reading the configuration file for the Web server or Web application. In some cases, the event logs may contain more information about what caused this error.

If you see the text "There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined", this error is because you are running a .NET Framework 3.5-based application in .NET Framework 4. If you are running WebMatrix, to resolve this problem, go to the Settings node to set the .NET Framework version to ".NET 2". You can also remove the extra sections from the web.config file.

エラー事例:2

以下のエラーが発生します。
エラーメッセージ
HTTP Error 500.19 - Internal Server Error
ページに関する構成データが無効であるため、要求されたページにアクセスできません。
エラーメッセージの詳細
Detailed Error Information:
Module IIS Web Core
Notification 不明
Hendler 未定義です
Error Code 0x80070003
構成エラー 構成ファイルを読み取れません
構成ファイル \\?\C:\(プロジェクトのフォルダ)\web.config
Requested URL https://localhost:nnnnn/(アプリケーションのパス)
Physical Path
Logon Method 未定義です
Logon User 未定義です
追加情報
More Information:
このエラーは、Web サーバーまたは Web アプリケーションの構成ファイルの読み取りに問題があるときに発生します。エラーの原因に関する情報が、イベント ログに記録されている場合があります。
ブラウザーに "重複する 'system.web.extensions/scripting/scriptResourceHandler' セクションが定義されています" というテキストが表示される場合は、.NET 3.5 ベースのアプリケーションを .NET Framework 4 で実行したことが原因です。WebMatrix を実行している場合は、この問題を解決するために、[設定] ノードに移動して、.NET Framework のバージョンを ".NET 2" に設定します。web.config ファイルの余分なセクションを削除することもできます。
エラーコードは Error Code 0x80070003 になります。
エラーメッセージでは、web.configファイルが読み取れない構成ファイルとして表示されており、何らかの原因でweb.configファイルが読み込めていないようです。

対処方法

.vsフォルダを削除します。.vsフォルダは隠しフォルダのため、エクスプローラーで見えない場合は隠しファイルを表示する設定に変更します。 詳しくはこちらの記事を参照してください。



削除後、プロジェクトを実行して正常に起動できるか確認します。

対処方法:旧バージョンのVisual Studio

suoファイルや関連ファイルを削除します。

ソリューションファイルのあるディレクトリにある".suo"ファイルと".vs"ディレクトリを削除します。



削除後、プロジェクトを実行して正常に起動できるか確認します。

対処方法 (Visual Studio 2022以降の場合)

Visual Studio 2022以降の場合、設定がテキストファイルのため、ファイルを変更する方法も利用できます。

以下のファイルをテキストエディタで開きます。
(ソリューションルート)/.vs/(ソリューション名)/config/applicationhost.config

起動できないプロジェクトのsiteタグのphysicalPath属性を確認すると、存在しないディレクトリを指しています。 正しいディレクトリに修正する方法でも対応できます。
applicationhost.config
<configuration>
 <!-- (中略) -->
  <system.applicationHost>
   <!-- (中略) -->

      <site name="(プロジェクト名)" id="nn">
        <application path="/" applicationPool="(アプリケーションプール名)">
          <virtualDirectory path="/" physicalPath="C:\Users\(存在しないユーザー名)\Documents\My Web Sites\(プロジェクト名)" />
          <virtualDirectory path="/xxx" physicalPath="(ソースコードのフォルダ)" />
        </application>
        <application path="/xxx/xxx" applicationPool="(アプリケーションプール名)">
          <virtualDirectory path="/" physicalPath="(ソースコードのフォルダ)" />
        </application>
        <bindings>
          <binding protocol="http" bindingInformation="*:59708:localhost" />
          <binding protocol="https" bindingInformation="*:44324:localhost" />
        </bindings>
      </site>

  </system.applicationHost>
</configuration>
著者
iPentecのメインプログラマー
C#, ASP.NET の開発がメイン、少し前まではDelphiを愛用
最終更新日: 2023-03-01
作成日: 2015-08-12
iPentec all rights reserverd.