CodeGrue
CodeGrue

Reputation: 5933

Get MVC Razor favor .cshtml over .aspx

I have converted a site over entirely to Razor and want it to ignore any residual .aspx files. These have caused problems by

  1. not being deleted from the production server and
  2. being recreated by NuGet packages. In this case, the ASPX takes precedence and any customization to the equivalent CSHTML file are not in play.

I would like to tell the entire site to stop processing ASPX or ASCX pages and only use Razor views.

Upvotes: 4

Views: 898

Answers (1)

Jakub Konecki
Jakub Konecki

Reputation: 46018

Add following to Global.asax.cs

protected void Application_Start()
{
    ViewEngines.Engines.Clear();
    ViewEngines.Engines.Add(new RazorViewEngine());
}

By default a WebFormViewEngine is included BEFORE RazorViewEngine.

Upvotes: 4

Related Questions