1 /* ****************************************************************************
\r
3 * Copyright (c) Microsoft Corporation. All rights reserved.
\r
5 * This software is subject to the Microsoft Public License (Ms-PL).
\r
6 * A copy of the license can be found in the license.htm file included
\r
7 * in this distribution.
\r
9 * You must not remove this notice, or any other, from this software.
\r
11 * ***************************************************************************/
\r
13 namespace System.Web.Mvc {
\r
14 using System.Diagnostics.CodeAnalysis;
\r
18 public class WebFormViewEngine : VirtualPathProviderViewEngine {
\r
20 private IBuildManager _buildManager;
\r
22 public WebFormViewEngine() {
\r
23 MasterLocationFormats = new[] {
\r
24 "~/Views/{1}/{0}.master",
\r
25 "~/Views/Shared/{0}.master"
\r
28 AreaMasterLocationFormats = new[] {
\r
29 "~/Areas/{2}/Views/{1}/{0}.master",
\r
30 "~/Areas/{2}/Views/Shared/{0}.master",
\r
33 ViewLocationFormats = new[] {
\r
34 "~/Views/{1}/{0}.aspx",
\r
35 "~/Views/{1}/{0}.ascx",
\r
36 "~/Views/Shared/{0}.aspx",
\r
37 "~/Views/Shared/{0}.ascx"
\r
40 AreaViewLocationFormats = new[] {
\r
41 "~/Areas/{2}/Views/{1}/{0}.aspx",
\r
42 "~/Areas/{2}/Views/{1}/{0}.ascx",
\r
43 "~/Areas/{2}/Views/Shared/{0}.aspx",
\r
44 "~/Areas/{2}/Views/Shared/{0}.ascx",
\r
47 PartialViewLocationFormats = ViewLocationFormats;
\r
48 AreaPartialViewLocationFormats = AreaViewLocationFormats;
\r
51 internal IBuildManager BuildManager {
\r
53 if (_buildManager == null) {
\r
54 _buildManager = new BuildManagerWrapper();
\r
56 return _buildManager;
\r
59 _buildManager = value;
\r
63 protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath) {
\r
64 return new WebFormView(partialPath, null);
\r
67 protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath) {
\r
68 return new WebFormView(viewPath, masterPath);
\r
71 [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",
\r
72 Justification = "Exceptions are interpreted as indicating that the file does not exist.")]
\r
73 protected override bool FileExists(ControllerContext controllerContext, string virtualPath) {
\r
75 object viewInstance = BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(object));
\r
76 return viewInstance != null;
\r
78 catch (HttpException he) {
\r
79 if (he is HttpParseException) {
\r
80 // The build manager found something, but instantiation failed due to a runtime lookup failure
\r
84 if (he.GetHttpCode() == (int)HttpStatusCode.NotFound) {
\r
85 // If BuildManager returns a 404 (Not Found) that means that a file did not exist.
\r
86 // If the view itself doesn't exist, then this method should report that rather than throw an exception.
\r
87 if (!base.FileExists(controllerContext, virtualPath)) {
\r
92 // All other error codes imply other errors such as compilation or parsing errors
\r