首页 > 解决方案 > 使用 AMP 项目和 Razor 页面的页面加载 8 次

问题描述

在这个使用 Razor 页面的最小 AMP HTML 页面(参见http://ampproject.com)中,每次加载页面时都会多次点击 OnGet 中的断点(通常是 8 次)。为什么会这样?谁能告诉我出了什么问题?先感谢您。

这里是c#。

using Microsoft.AspNetCore.Mvc.RazorPages;
namespace iVoterGuide.com.Pages {
    public class IndexModel : PageModel {
        public void OnGet() {
            // ***** The breakpoint is set here
        }
    }
}

这是cshtml。如您所见,它仅包含 AMP 所需的最少脚本和其他内容,以及“TEST BODY”内容。

@page
@model iVoterGuide.com.Pages.IndexModel
@{
    Layout = null;
}

<!DOCTYPE html>
<html ⚡&gt;
<head>
    <meta charset="utf-8">
    <link rel="canonical" href="IndexWholePage.cshtml">
    <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"/>
    <title>IndexWholePage</title>
    <!-- Structured Data
    –––––––––––––––––––––––––––––––––––––––––––––––––– -->
    <!-- JSON-LD -->
    <script type="application/ld+json">
        {
        "@@context": "http://schema.org",
        "@@type": "NewsArticle",
        "headline": "page title",
        "datePublished": "2018-05-19 14:52",
        "image": [
        "logo.jpg"
        ]
        }
    </script>
    <!-- Facebook -->
    <meta property="og:url" content="page url" />
    <meta property="og:title" content="page title" />
    <meta property="og:image" content="document image" />
    <meta property="og:description" content="document description" />
    <meta property="og:site_name" content="iVoterGuide" />
    <meta property="og:type" content="article" />
    <meta property="og:locale" content="en_US" />
    <meta property="og:fb:app_id" content="" />
    <!-- Twitter -->
    <meta name="twitter:site" content="@@iVoterGuide" />
    <meta name="twitter:creator" content=" " />
    <!-- Boilerplate Scripts/Styles
    –––––––––––––––––––––––––––––––––––––––––––––––––– -->
            <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
    <noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>

    <!-- Fonts & Icons
    –––––––––––––––––––––––––––––––––––––––––––––––––– -->
    <link href="https://fonts.googleapis.com/css?family=Roboto:200,300,400,500,700" rel="stylesheet">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <script async src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>
    <h1>TEST BODY</h1>
</body>
</html>

如果我从 ⚡ 中删除,那么一切正常。

编辑:简化并更新了问题。

标签: c#amp-htmlrazor-pages

解决方案


推荐阅读