I'd like to use the Visual Studio 2010 MVC 3 framework for a web project that hosts VXML and CCXML rather than HTML for telephony based applications.
MVC 3 seems ideally suited to this kind of application, and I think it's a great alternative to the more widely used jsp/Tomcat based applications that are generally used for VXML/CCXML. But there are a couple of annoyances:
Response.ContentType = "text/vxml";
in every Action Method?You could write a custom view engine based on the Razor view engine and register a custom extension for your views:
public class VXMLViewEngine : RazorViewEngine
{
public VXMLViewEngine()
{
ViewLocationFormats = new[] { "~/Views/{1}/{0}.vxml", "~/Views/Shared/{0}.vxml" };
MasterLocationFormats = new[] { "~/Views/{1}/{0}.vxml", "~/Views/Shared/{0}.vxml" };
PartialViewLocationFormats = new[] { "~/Views/{1}/{0}.vxml", "~/Views/Shared/{0}.vxml" };
FileExtensions = new[] { "vxml" };
}
protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
{
controllerContext.HttpContext.Response.ContentType = "text/vxml";
return base.CreateView(controllerContext, viewPath, masterPath);
}
}
and in Application_Start declare the custom extension:
RazorCodeLanguage.Languages.Add("vxml", new CSharpRazorCodeLanguage());
WebPageHttpHandler.RegisterExtension("vxml");
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new VXMLViewEngine());
and the custom build provider in web.config that will recognize the .vxml
extension:
<compilation debug="true" targetFramework="4.0">
<assemblies>
...
</assemblies>
<buildProviders>
<add extension=".vxml" type="System.Web.WebPages.Razor.RazorBuildProvider, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</buildProviders>
</compilation>
Now you could use .vxml
as extension for the views. Since Visual Studio doesn't recognize the .vxml
extension, when you open a file with it, it won't bother you with warnings. And you could even create a custom VS plugin that could provide syntax highlighting and Intellisense for this custom extension.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With