An unhandled exception occurred while processing the request.
AmbiguousMatchException: The request matched multiple endpoints. Matches:
(ページ名1)
(ページ名2)
Razor Pages アプリケーションで "An unhandled exception occurred while processing the request. AmbiguousMatchException: The request matched multiple endpoints. Matches:" エラーが発生する現象について紹介します。
Razor Pagesアプリケーションでページにアクセスすると以下のエラーが発生します。
または
複数のページが同じURLで衝突している可能性が高いです。
下記2つのRazor PageがWebアプリケーション内に存在している場合、どちらかのRazor Pageにアクセスするとエラーが発生します。
@page "/TestPage"
@{
}
<html>
<head>
</head>
<body>
<h2>TestPage1</h2>
<p>テストページ1です。</p>
</body>
</html>
@page "/TestPage"
@{
}
<html>
<head>
</head>
<body>
<h2>TestPage2</h2>
<p>テストページ2です。</p>
</body>
</html>
TestPage1.cshtml と TestPage2.cshtml のページがありますが、@page
ディレクティブではどちらも /TestPage
が指定されています。
このためどちらのページも (アプリケーションルート/TestPage)
でページが表示される動作となりページの衝突が起きてしまい、エラーが発生します。
この場合のエラーメッセージが以下となります。
回避方法はそれぞれの@page
ディレクティブが衝突しないよう別のパスを設定します。