diff --git a/src/Microsoft.AspNet.Mvc.Razor/Properties/Resources.Designer.cs b/src/Microsoft.AspNet.Mvc.Razor/Properties/Resources.Designer.cs
index d4bc086a0c..a484794c7e 100644
--- a/src/Microsoft.AspNet.Mvc.Razor/Properties/Resources.Designer.cs
+++ b/src/Microsoft.AspNet.Mvc.Razor/Properties/Resources.Designer.cs
@@ -203,6 +203,22 @@ namespace Microsoft.AspNet.Mvc.Razor
return string.Format(CultureInfo.CurrentCulture, GetString("SectionsNotRendered"), p0);
}
+ ///
+ /// View '{0}' must have extension '{1}' when the view represents a full path.
+ ///
+ internal static string ViewMustEndInExtension
+ {
+ get { return GetString("ViewMustEndInExtension"); }
+ }
+
+ ///
+ /// View '{0}' must have extension '{1}' when the view represents a full path.
+ ///
+ internal static string FormatViewMustEndInExtension(object p0, object p1)
+ {
+ return string.Format(CultureInfo.CurrentCulture, GetString("ViewMustEndInExtension"), p0, p1);
+ }
+
///
/// The method '{0}' cannot be invoked by this view.
///
diff --git a/src/Microsoft.AspNet.Mvc.Razor/Resources.resx b/src/Microsoft.AspNet.Mvc.Razor/Resources.resx
index 57bb7845be..df7106bffa 100644
--- a/src/Microsoft.AspNet.Mvc.Razor/Resources.resx
+++ b/src/Microsoft.AspNet.Mvc.Razor/Resources.resx
@@ -150,6 +150,9 @@
The following sections have been defined but have not been rendered: '{0}'.
+
+ View '{0}' must have extension '{1}' when the view represents a full path.
+
The method '{0}' cannot be invoked by this view.
diff --git a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs
index 82d2fe48fc..04c495209d 100644
--- a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs
+++ b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs
@@ -25,17 +25,19 @@ namespace Microsoft.AspNet.Mvc.Razor
{
public class RazorViewEngine : IViewEngine
{
+ private static readonly string _viewExtension = ".cshtml";
+
private static readonly string[] _viewLocationFormats =
{
- "/Views/{1}/{0}.cshtml",
- "/Views/Shared/{0}.cshtml",
+ "/Views/{1}/{0}" + _viewExtension,
+ "/Views/Shared/{0}" + _viewExtension,
};
private static readonly string[] _areaViewLocationFormats =
{
- "/Areas/{2}/Views/{1}/{0}.cshtml",
- "/Areas/{2}/Views/Shared/{0}.cshtml",
- "/Views/Shared/{0}.cshtml",
+ "/Areas/{2}/Views/{1}/{0}" + _viewExtension,
+ "/Areas/{2}/Views/Shared/{0}" + _viewExtension,
+ "/Views/Shared/{0}" + _viewExtension,
};
private readonly IVirtualPathViewFactory _virtualPathFactory;
@@ -70,6 +72,8 @@ namespace Microsoft.AspNet.Mvc.Razor
if (nameRepresentsPath)
{
+ EnsureFullPathViewExtension(viewName);
+
var view = _virtualPathFactory.CreateInstance(viewName);
return view != null ? ViewEngineResult.Found(viewName, view) :
ViewEngineResult.NotFound(viewName, new[] { viewName });
@@ -93,6 +97,15 @@ namespace Microsoft.AspNet.Mvc.Razor
}
}
+ private static void EnsureFullPathViewExtension(string viewName)
+ {
+ if(!viewName.EndsWith(_viewExtension))
+ {
+ throw new InvalidOperationException(
+ Resources.FormatViewMustEndInExtension(viewName, _viewExtension));
+ }
+ }
+
private static bool IsSpecificPath(string name)
{
char c = name[0];