Skip to main content

Embedded Web Application

An embedded web application allows deploying a web application as an assembly reference and mapping its root controller an MVC route in the host application. This is accomplished by using the MVC Code Routing open source component. Using namespace-based routing, instead of conventional MVC routing, routes don’t need to be configured and are dynamically found by using the root controller namespace. This reduces NuGet upgrade issues with deploying individual files web application files in a host process as the whole module application can be deployed as a project reference.

Creating an embedded web application is the same as creating any other web application. One key difference is that you must set the property for all views in the application for “Build Action” to “Embedded Resource”. This is found in the Visual Studio property window for the view. This will embed the view in the assembly so that it can be found by the dynamic routing engine in the host application. It is recommended for debugging purposes to create the controllers/models/views in the host application first, then once working, move then to the embedded web application.

Examining the Eleflex.Email.Web.Admin project, it contains controllers, models and views as any other web application would. In order to register this embedded web application in a host application, we need to add an MVC route configuration. For the default system components, this is found in web server and web client applications in the App_Start/Eleflex_Start/WebRoutesStartupTask.

When installing new ELEFLEX® Modules, developers should try not to modify any existing files in an ELEFLEX® installation. Instead, create new files specific to your module and use the startup conventions to configure and register your module.

The next example shows how the Eleflex.Email module configures its embedded admin web application route into the host process. This is found in the App_Start/Eleflex_Start/EleflexEmail/WebClientRoutesStartupTask.cs file. This will set the host web application route for “/Admin/Email” to point to the Eleflex.Email.Web.Admin project’s AdminController and all web requests will be funneled to this application.


using System.Web.Routing;
using Eleflex;
using MvcCodeRouting;
namespace WebServer.App_Start.Eleflex_Start.EleflexEmail
{
    /// <summary>
    /// Represents a startup task for configuring routes in the web application.
    /// </summary>
    public partial class WebClientRoutesStartupTask : StartupTask
    {
        /// <summary>
        /// Constructor.
        /// </summary>
        public WebClientRoutesStartupTask() : base()
        {
            Description = "This task registers mvc routes used for the ELEFLEX Email Module.";
            Priority = StartupConstants.PRIORITY_CUSTOM;
        }
        /// <summary>
        /// Start processing logic.
        /// </summary>
        /// <param name="taskOptions"></param>
        /// <returns></returns>
        public override bool Start(ITaskOptions taskOptions)
        {
            //CONFIGURE ROUTE FOR ADMIN/Email
            RouteTable.Routes.MapCodeRoutes(
               baseRoute: "Admin/Email",
               rootController: typeof(Eleflex.Email.Web.Admin.Controllers.AdminController),
               settings: new CodeRoutingSettings
               {
                   EnableEmbeddedViews = true,
               }
            );
            return base.Start(taskOptions);
        }
    }
}