首页 > 解决方案 > 发布时缺少 ASP.net CORE 3.1 视图

问题描述

我开发了一个 ASP.net CORE 3.1 应用程序。我最近购买了一个域并将我的项目发布到 Windows 共享主机中,因此我无法访问 IIS。

当我启动我的应用程序时,我得到以下信息:

2020-06-22 23:02:21.411 +02:00 [INF] Application started. Press Ctrl+C to shut down.
2020-06-22 23:02:21.411 +02:00 [INF] Hosting environment: Production
2020-06-22 23:02:21.411 +02:00 [INF] Content root path: E:\kunden\homepages\24\d833115679\www\dev
2020-06-22 23:02:21.430 +02:00 [INF] Request starting HTTP/1.1 GET https://dev.mywebsite.com/  
2020-06-22 23:02:21.486 +02:00 [INF] Authorization failed.
2020-06-22 23:02:21.490 +02:00 [INF] AuthenticationScheme: CookieAuthentication was challenged.
2020-06-22 23:02:21.501 +02:00 [INF] Request finished in 73.8851ms 302 
2020-06-22 23:02:22.852 +02:00 [INF] Request starting HTTP/1.1 GET https://dev.mywebsite.com/EspaceProprietaire/Connexion?ReturnUrl=%2F  
2020-06-22 23:02:22.863 +02:00 [INF] Executing endpoint 'utpmv.api.Controllers.EspaceProprietaireController.Connexion (utpmv.api)'
2020-06-22 23:02:22.881 +02:00 [INF] Route matched with {action = "Connexion", controller = "EspaceProprietaire"}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult Connexion() on controller utpmv.api.Controllers.EspaceProprietaireController (utpmv.api).
2020-06-22 23:02:22.897 +02:00 [INF] Executing ViewResult, running view Connexion.
2020-06-22 23:02:22.899 +02:00 [ERR] The view 'Connexion' was not found. Searched locations: ["/Views/EspaceProprietaire/Connexion.cshtml","/Views/Shared/Connexion.cshtml"]
2020-06-22 23:02:22.911 +02:00 [INF] Executed action utpmv.api.Controllers.EspaceProprietaireController.Connexion (utpmv.api) in 24.7936ms
2020-06-22 23:02:22.912 +02:00 [INF] Executed endpoint 'utpmv.api.Controllers.EspaceProprietaireController.Connexion (utpmv.api)'
2020-06-22 23:02:22.914 +02:00 [ERR] An unhandled exception has occurred while executing the request.
System.InvalidOperationException: The view 'Connexion' was not found. The following locations were searched:
/Views/EspaceProprietaire/Connexion.cshtml
/Views/Shared/Connexion.cshtml

在已发布的文件夹中,我没有任何视图,但我有 utpmv.api.Views.dll。我知道在 CORE 3.1 中,视图是预编译的,因此视图不作为 cshtml 文件存在是有道理的。

但是,我尝试将它们添加到所有其他已发布文件的同一级别,但我仍然遇到同样的问题。视图丢失和/或应用程序找不到它们。当然,我的项目在本地使用 IIS Express 可以完美运行。

这是我的发布配置:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <DeleteExistingFiles>True</DeleteExistingFiles>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <PublishProvider>FileSystem</PublishProvider>
    <PublishUrl>bin\Release\publish\</PublishUrl>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <SiteUrlToLaunchAfterPublish />
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RuntimeIdentifier>win-x86</RuntimeIdentifier>
    <ProjectGuid>a9405909-b7a5-4293-9103-67301e71a0b4</ProjectGuid>
    <SelfContained>false</SelfContained>
  </PropertyGroup>
</Project>

我查看了在线和stackoverflow,但没有找到答案。

你们有什么想法吗?

非常感谢您的帮助。

标签: asp.net-core.net-core

解决方案


我将视图的构建操作从无更新为内容。此操作删除了我的 csproj 中的许多行,现在我的项目工作正常。

但是我不知道为什么我必须更改此设置。我的发布文件夹中没有任何新的 dll 或文件夹。

如果有人能给我们一个清晰的解释,这将有助于理解为什么默认配置不允许视图工作。


推荐阅读