Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with ASP WebApi #37

Open
Cristiian opened this issue Sep 14, 2019 · 0 comments
Open

Usage with ASP WebApi #37

Cristiian opened this issue Sep 14, 2019 · 0 comments

Comments

@Cristiian
Copy link

Hello, I'm trying to use this library for email templating in ASP web Api, I'm using the UseAppdomain Option, but is unable to load the Westwind.Razor dll, I have set the BaseBinaryFolder to the path where all the dll's exists, but the error is the same, if I use the UseAppdomain = false, everything works fine, I tried this with a console application, and works with no issue

Web Api Structure (root path)
c:\...\
imagen

this is the class for the renderer I'm Using

public class RazorTemplates : IDisposable
    {
        RazorFolderHostContainer Host { get; set; }

        public RazorTemplates()
        {
            string ServerMapPath = HttpContext.Current.Server.MapPath("~"); // c:\\...\ root path

            Host = new RazorFolderHostContainer()
            {
                // *** Set your Folder Path here - physical or relative ***
                TemplatePath = Path.Combine(ServerMapPath, "Views", "Email"),//c:\\...\Views\Email
                // *** Path to the Assembly path of your application
                BaseBinaryFolder = Path.Combine(ServerMapPath, "bin"), //c:\\...\bin
                UseAppDomain = true,
                ThrowExceptions = true
            };

            Host.Start();
        }

        public string RenderTemplate(string template, object model)
        {
            string result = Host.RenderTemplate(template, model);
            if (result == null)
            {
                throw new InvalidOperationException(Host.ErrorMessage);
            }
            return result;
        }

        public void Dispose()
        {
            Host.Stop();
            Host.Dispose();
        }
    }

Rendering a template

            using (RazorTemplates host = new RazorTemplates())
            {
                return Ok(host.RenderTemplate("~/_PartialPage1.cshtml", new { }));
            }

The exception:

imagen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant