1
  1. 我们有很多视图我已经转移到 Razor,因为我讨厌 WebForms,而且我们没有太多需要更改的视图,但是在 Webforms 中还有一些我还没有得到。我们在 .ascx 中也有一些部分视图,我还没有将其中的任何一个移到 Razor,但它们在 WebForms 和 Razor 视图中都被引用。
  2. 我们也有大部分观点的移动版本。如果我将视图的非移动版本更改为 Razor,我也更改了移动版本。我们在网站上有一个按钮,可让您通过设置 cookie 手动选择切换到移动视图或标准视图。

当没有 Razor 视图时,视图引擎看起来像这样

ViewEngines.Clear();
ViewEngines.Engines.Add(new MobileCapableWebFormViewEngine("Mobile", Controllers.SafetyLineController.MobileViewFormatChooser) { NotSupportedViewName = "HttpExceptionNotImplemented.Mobile" });
ViewEngines.Engines.Add(new WebFormViewEngine());

然后我将其更改为以下

ViewEngines.Clear();
ViewEngines.Engines.Add(new MobileCapableRazorViewEngine("Mobile", Controllers.SafetyLineController.MobileViewFormatChooser));
ViewEngines.Engines.Add(new MobileCapableWebFormViewEngine("Mobile", Controllers.SafetyLineController.MobileViewFormatChooser) { NotSupportedViewName = "HttpExceptionNotImplemented.Mobile" });
ViewEngines.Engines.Add(new RazorViewEngine());
ViewEngines.Engines.Add(new WebFormViewEngine());

这对于普通视图来说效果很好,但是整个站点的移动视图完全被破坏了。无论您是通过实际的移动设备还是使用按钮,点击任何移动页面都会在浏览器中显示空白屏幕。调试并不是特别有用,因为只有在站点部署到开发机器上的 IIS 服务器后才会发生这种情况。本地测试完全正常(我们在本地使用内置的 ASP.NET Web 服务器)。

视图引擎设置似乎存在一些问题,但我无法从我的谷歌搜索中弄清楚这是什么。

白屏发生时我得到的错误是

Exception Thrown:
Type: System.InvalidOperationException
Message: The view at '~/Views/User/History.Mobile.aspx' must derive from WebViewPage, or WebViewPage<TModel>.
Source: System.Web.Mvc

所以我猜一般来说,当加载任何 .aspx 或 .ascx 移动视图时,就会出现问题。

4

0 回答 0