你可以寫基礎上,Razor視圖引擎的自定義視圖引擎和註冊自定義擴展您的觀點:
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);
}
}
和申報的Application_Start自定義擴展:
RazorCodeLanguage.Languages.Add("vxml", new CSharpRazorCodeLanguage());
WebPageHttpHandler.RegisterExtension("vxml");
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new VXMLViewEngine());
,並在web.config中的自定義生成提供程序將RECO gnize的.vxml
擴展:
<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>
現在你可以使用.vxml
作爲擴展的意見。由於Visual Studio無法識別.vxml
擴展名,因此當您用它打開文件時,它不會打擾您的警告。你甚至可以創建一個自定義VS插件,爲這個自定義擴展提供語法突出顯示和Intellisense。
對於第2點 - 只是使用基本控制器類型和覆蓋,也許,OnResultExecuting或OnActionExecuting – 2012-03-09 11:54:04
@AndrasZoltan:啊是的,我應該想到這個我自己......謝謝。 – BG100 2012-03-09 12:06:24