Skip to content

Usage with ASP WebApi #37

@Cristiian

Description

@Cristiian

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions