[英]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.