简体   繁体   English

访问在 azure 服务器上运行的 .net 核心应用程序中的共享视图文件夹

[英]Access shared view folder in a .net core application running on an azure server

While running my site locally, I was accessing files in the shared view folder like this:在本地运行我的站点时,我正在访问共享视图文件夹中的文件,如下所示:

string[] files = Directory.GetFiles("Views/Shared");

because I am getting page content dynamically through an API call, and some of the fields have partial views written to override the default rendering.因为我通过 API 调用动态获取页面内容,并且某些字段具有写入的部分视图以覆盖默认呈现。 I just grab the shared views name that match some content in the api call, set it in a variable, then use that variable to render the partial view in the.cshtml page.我只是在 api 调用中获取与某些内容匹配的共享视图名称,将其设置在一个变量中,然后使用该变量在 .cshtml 页面中呈现部分视图。

This works fine locally, but failed after deploying to Azure, but some googling told me that the method I should access project files is using IWebHostEnvironment.ContentRootPath.这在本地工作正常,但在部署到 Azure 后失败,但一些谷歌搜索告诉我,我应该访问项目文件的方法是使用 IWebHostEnvironment.ContentRootPath。 Again, that works fine locally;同样,这在本地工作得很好; but after deploying to Azure, the folder structure changes so that the /views/shared folder (or any project folders other than wwwroot) doesn't exist.但是在部署到 Azure 之后,文件夹结构发生了变化,因此 /views/shared 文件夹(或除 wwwroot 之外的任何项目文件夹)不存在。 I think azure is just building the project as there is a views.dll file;认为azure 只是在构建项目,因为有一个 views.dll 文件; but now I don't know how to set these filenames into variables in my model.但现在我不知道如何将这些文件名设置为我的 model 中的变量。

Is there a way to iterate over my /views/shared folder after deploying?部署后有没有办法遍历我的 /views/shared 文件夹?

after deploying to Azure, the folder structure changes so that the /views/shared folder (or any project folders other than wwwroot) doesn't exist.部署到 Azure 后,文件夹结构发生变化,因此 /views/shared 文件夹(或除 wwwroot 之外的任何项目文件夹)不存在。 I think azure is just building the project as there is a views.dll file;我认为 azure 只是在构建项目,因为有一个 views.dll 文件; but now I don't know how to set these filenames into variables in my model.但现在我不知道如何将这些文件名设置为我的 model 中的变量。

You can try to set CopyRazorGenerateFilesToPublishDirectory property to true , which would help copy RazorGenerate items (.cshtml) files to the publish directory.您可以尝试将CopyRazorGenerateFilesToPublishDirectory属性设置为true ,这将有助于将 RazorGenerate 项目 (.cshtml) 文件复制到发布目录。

<PropertyGroup>

  <!--other properties here-->

  <CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory>
  
  <!--other properties here-->

</PropertyGroup>

For more information, please check the following doc:有关更多信息,请查看以下文档:

https://docs.microsoft.com/en-us/aspnet/core/razor-pages/sdk?view=aspnetcore-5.0#properties https://docs.microsoft.com/en-us/aspnet/core/razor-pages/sdk?view=aspnetcore-5.0#properties

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET 核心授权权限访问文件夹与Identity Server - ASP.NET Core authorization permission access folder with Identity Server 无法在EC2上运行的Cant访问点网核心应用程序 - Cant access dot net core application running on ec2 Azure WorkerRole共享文件夹访问被拒绝 - Azure WorkerRole shared folder access denied 运行Kestrel服务器时构建.NET核心应用程序 - Build a .NET core application while running Kestrel server Asp.Net Core 2.2身份页面不适用于View / Shared文件夹中的Layout - Asp.Net Core 2.2 Identity pages wont work with Layout in View/Shared folder 如何检查ASP.NET Core MVC的共享文件夹中是否存在视图? - How to check if a view exist in shared folder in ASP.NET Core MVC? 在.NET Core Web应用程序中存储Identity Server的访问令牌 - Storing access token from Identity Server in NET Core web application 运行 .NET 核心控制台应用程序 - Running a .NET Core Console Application 如何访问正在运行的.net应用程序 - How to access a running .net application 如何从在容器中运行的 ASP.NET 核心应用程序连接到具有集成安全性的 Windows 服务器上的 SQL 服务器 - How to connect from ASP.NET Core application running in a container to SQL Server on Windows Server with Integrated Security
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM