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 ViewLocationFormats = new[] {
\r
29 "~/Views/{1}/{0}.aspx",
\r
30 "~/Views/{1}/{0}.ascx",
\r
31 "~/Views/Shared/{0}.aspx",
\r
32 "~/Views/Shared/{0}.ascx"
\r
35 PartialViewLocationFormats = ViewLocationFormats;
\r
38 internal IBuildManager BuildManager {
\r
40 if (_buildManager == null) {
\r
41 _buildManager = new BuildManagerWrapper();
\r
43 return _buildManager;
\r
46 _buildManager = value;
\r
50 protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath) {
\r
51 return new WebFormView(partialPath, null);
\r
54 protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath) {
\r
55 return new WebFormView(viewPath, masterPath);
\r
58 [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",
\r
59 Justification = "Exceptions are interpreted as indicating that the file does not exist.")]
\r
60 protected override bool FileExists(ControllerContext controllerContext, string virtualPath) {
\r
62 object viewInstance = BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(object));
\r
64 return viewInstance != null;
\r
66 catch (HttpException he) {
\r
67 if (he.GetHttpCode() == (int)HttpStatusCode.NotFound) {
\r
68 // If BuildManager returns a 404 (Not Found) that means the file did not exist
\r
72 // All other error codes imply other errors such as compilation or parsing errors
\r