Setup folder structure:
Create a new asp.net application not a mvc application just a standard asp.net application. This means you will not get the mvc helpers for creating controllers and views but that’s not a massive loss and has the advantage that you don’t need the asp.net mvc installed if you open the solution on another machine.
The default.aspx placeholder is required to allow the asp.net routing to work.
Delete the code behind files for Default.aspx (Default.aspx.cs, Default.aspx.designer.cs) they are not needed.
Add references to the Spark.dll and Spark.Web.Mvc.dll located in the libs folder.
Add references to asp.net mvc System.Web.Routing.dll, System.Web.Abstractions.dll, System.Web.Mvc.dll
Add spark to the web.config:
<section name=”spark” type=”Spark.Configuration.SparkSectionHandler, Spark”/>
Debug true shows compilation errors when rendering views.
Add routing to httpModules section of web.config:
Add a application.cs which creates the routes and registers the spark view engine:
public class Application
public void RegisterRoutes(IList
public void RegisterViewEngine(IList
Add a global.asax with the following code behind.
public class Global : HttpApplication
protected void Application_Start(object sender, EventArgs e)
var app = new Application();
protected void Application_BeginRequest(object sender, EventArgs e)
string path = Request.AppRelativeCurrentExecutionFilePath;
if (string.Equals(path, “~/default.aspx”, StringComparison.InvariantCultureIgnoreCase) ||
Create content, controllers and view folders in the root of the asp.net project:
Create a shared folder in the views folder with a _global.spark file this will be used to share come code with all views.
Create a layouts folder in the views folder with a file called application.spark which will be used for the layout of the application very much like a master page.
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
The use content view tag highlighted above is replaced by the current view returned by asp.net mvc.
Add a HomeController.cs under the controllers folder with the following content:
public class HomeController : Controller
public ActionResult Index()
Under the views folder create a home\index.spark with the following content:
Run the project and you should get:
You can download this sample solution here.