How do I solve a “view not found” exception in asp.net core mvc project

前端 未结 16 1978
梦毁少年i
梦毁少年i 2020-12-09 15:53

I\'m trying to create a ASP.NET Core MVC test app running on OSX using VS Code. I\'m getting a \'view not found\' exception when accessing the default Home/index (or any oth

16条回答
  •  青春惊慌失措
    2020-12-09 16:09

    I had this same issue while building an Identity Server instance, everything worked great if I ran the project from Visual Studio but after publishing the project and running with the dotnet command I got the "View not found" error when Identity Server tried to serve up the Login view. I already had verified everything else mentioned here but it still wasn't working. I finally found that the problem was with how I Was running the dotnet command. I was running it from the parent folder, one level above my Identity Server instance and this affected the content root path, for example, running this

    dotnet myWebFolder/MyIdentityServer.dll
    

    gave me the following output when Identity Server started:

    So, the full path of my dll in this case is C:\inetpub\aspnetcore\myWebFolder\MyIdentityServer.dll and I ran the dotnet command from the C:\inetpub\aspnetcore\ folder.

    To get the correct content root I had to make sure I ran the dotnet command from the same folder where the dll is, as in 'dotnet MyIdentityServer.dll`. That change gave me this output:

    Now my content root path is correct and Identity Server finds the Login views at C:\inetpub\aspnetcore\myWebFolder\Views\Account\Login.cshtml

提交回复
热议问题