Starts in:
1 DAY
19 HRS
19 MIN
54 SEC
Starts in:
1 D
19 H
19 M
54 S
Open Closed

VirtualFileSystem not working in deployed application to IIS #4673


User avatar
0
AdamMusson created

If you're creating a bug/problem report, please include followings:

  • ABP Framework version: v7.0.1
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): No
  • Exception message and stack trace: Could not find a file/folder at the location: /Templates/ConfirmEmail.cshtml
  • Steps to reproduce the issue: I have followed steps in articles for overriding the registermodel with a custom one that has some steps for my application's registration. The EmailTemplate for the ConfirmEmail is located in the Templates directory in the DomainModule project. The system sends the email and everything works fine locally but when it is deployed to IIS the VirtualFileSystem is not picking up the /Templates/ConfirmEmail.cshtml even though it is an embedded resource.

I have this code in the WebModule to configure the VirtualFIleSystem

 private void ConfigureVirtualFileSystem(IWebHostEnvironment hostingEnvironment)
    {
        Configure<AbpVirtualFileSystemOptions>(options =>
        {
            options.FileSets.AddEmbedded<HourcoinWebModule>();
            options.FileSets.AddEmbedded<HourcoinDomainModule>(
                 baseNamespace: "Hourcoin.Templates",
                 baseFolder: "/Templates");

            options.FileSets.AddEmbedded<RegistrationDomainModule>();
            


            if (hostingEnvironment.IsDevelopment())
            {

                options.FileSets.ReplaceEmbeddedByPhysical<HourcoinDomainSharedModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}Hourcoin.Domain.Shared", Path.DirectorySeparatorChar)));
                options.FileSets.ReplaceEmbeddedByPhysical<HourcoinDomainModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}Hourcoin.Domain", Path.DirectorySeparatorChar)));
                options.FileSets.ReplaceEmbeddedByPhysical<HourcoinApplicationContractsModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}Hourcoin.Application.Contracts", Path.DirectorySeparatorChar)));
                options.FileSets.ReplaceEmbeddedByPhysical<HourcoinApplicationModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}Hourcoin.Application", Path.DirectorySeparatorChar)));
                options.FileSets.ReplaceEmbeddedByPhysical<HourcoinHttpApiModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}Hourcoin.HttpApi", Path.DirectorySeparatorChar)));
                options.FileSets.ReplaceEmbeddedByPhysical<HourcoinWebModule>(hostingEnvironment.ContentRootPath);
            }
        });
    }

This works in development as the Physical File is used using the above ReplaceEmbeddedByPhysical. When deployed to IIS at myasp.net the email is not working because the template is not being rendered. I have caught the error and displayed it in the following screenshot image.

I have made sure the files in the Templates directory are Embedded Resources.

What could I be missing? Any help or suggestions would be appreciated .as i have followed all the documentation I can find and have not had any luck. I keep getting the error even after specifically ensuring the environment is Production in the web.c onfig which shouldn't be necessary. Is there a bug in the VirtualFIleSystem?


7 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you reproduce this in the template project and share it with me? liming.ma@volosoft.com

  • User Avatar
    0
    AdamMusson created

    Hi, I have shared a demo project Github repository with you so you can see a project based on the template project illustrating the problem. The code connects to the same database that has been deployed to myasp.net and as you can see works in Debug on the local machine.

    http://vfsdemo-001-site1.btempurl.com/ Is the Url you can see the code is deployed to. When you run it here and try to register the registration will fail because the ConfirmEmail template can't be found.

    On localhost the code works because of the ReplaceEmbeddedAsPhysical. On the deployed version it doesn't work because the EmbeddedFiles aren't being found in the virtualfilesyste,.

    Everything else is the same as both the local and deployed code are pointing to the same database. Any help in what I have done wrong here, if it isn't a bugm, would be helpful.

    Let me know if you need anything else. Thanks

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    <Project Sdk="Microsoft.NET.Sdk">
    
      <Import Project="..\..\common.props" />
    
      <PropertyGroup>
        <TargetFramework>net7.0</TargetFramework>
        <RootNamespace>VFSDemo</RootNamespace>
        <GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
      </PropertyGroup>
    
      <ItemGroup>
        <PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="7.0.0" />
      </ItemGroup>
    
      <ItemGroup>
        <EmbeddedResource Include="Templates\ConfirmEmail.cshtml" />
        <Content Remove="Templates\ConfirmEmail.cshtml" />
      </ItemGroup>
      
      <ItemGroup>
        <ProjectReference Include="..\VFSDemo.Domain.Shared\VFSDemo.Domain.Shared.csproj" />
      </ItemGroup>
    
      <ItemGroup>
        <PackageReference Include="Volo.Abp.Emailing" Version="7.0.1" />
        <PackageReference Include="Volo.Abp.Caching" Version="7.0.1" />
        <PackageReference Include="Volo.Abp.MailKit" Version="7.0.1" />
        <PackageReference Include="Volo.Abp.PermissionManagement.Domain.Identity" Version="7.0.1" />
        <PackageReference Include="Volo.Abp.PermissionManagement.Domain" Version="7.0.1" />
        <PackageReference Include="Volo.Abp.BackgroundJobs.Domain" Version="7.0.1" />
        <PackageReference Include="Volo.Abp.AuditLogging.Domain" Version="7.0.1" />
        <PackageReference Include="Volo.Abp.FeatureManagement.Domain" Version="7.0.1" />
        <PackageReference Include="Volo.Abp.SettingManagement.Domain" Version="7.0.1" />
        <PackageReference Include="Volo.Abp.BlobStoring.Database.Domain" Version="7.0.1" />
        <PackageReference Include="Volo.Abp.Identity.Pro.Domain" Version="7.0.1" />
        <PackageReference Include="Volo.Abp.LanguageManagement.Domain" Version="7.0.1" />
        <PackageReference Include="Volo.Abp.TextTemplating.Razor" Version="7.0.1" />
        <PackageReference Include="Volo.Saas.Domain" Version="7.0.1" />
        <PackageReference Include="Volo.Abp.TextTemplateManagement.Domain" Version="7.0.1" />
        <PackageReference Include="Volo.Abp.Commercial.SuiteTemplates" Version="7.0.1" />
        <PackageReference Include="Volo.Abp.Gdpr.Domain" Version="7.0.1" />
      </ItemGroup>
    
    </Project>
    
    public class VFSDemoDomainModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            //...
            Configure<AbpRazorTemplateCSharpCompilerOptions>(options =>
            {
                options.References.Add(MetadataReference.CreateFromFile(typeof(VFSDemoDomainModule).Assembly.Location));
            });
            Configure<AbpVirtualFileSystemOptions>(options =>
            {
                options.FileSets.AddEmbedded<VFSDemoDomainModule>();
            });
            //...
        }
    }
    
    
  • User Avatar
    0
    AdamMusson created

    I've made those changes and redeployed the app again but I am still getting the error that it can't find the embedded files when the app is deployed. It runs fine locally.

    Have you run on this on a deployed version or just locally on your machine? Because it sends me the email too when run on localhost connected to the database but as soon as I run it on the deployment server it complains about not being able to find the embedded files.

    I've made the changes and uploaded them to the Github.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Did you add the Microsoft.Extensions.FileProviders.Embedded as well?

    https://github.com/DrMuss/VFSDemo/commit/3a1045fe880578ce82416aa383e180547d4d45e5

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    You can set the environment to Production to test locally.

    https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-7.0

  • User Avatar
    0
    AdamMusson created

    Thanks, adding Microsoft.Extensions.FileProviders.Embedded did the trick. It works now so you can close this question and consider it answered.

    Thanks for your help!

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06