如何将 AdSense 代码添加到我的 ASP.NET MVC 网站?

我正在为我的网络应用程序设置 AdSense。我得到了一个 AdSense 代码,可以粘贴到我网站的 HTML 中的 和 标记之间。但是我在网站上使用 ASP.NET MVC。请问,如何在我的网站上使用此 AdSense 代码?


<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

<script>

   (adsbygoogle = window.adsbygoogle || []).push({

   google_ad_client: "ca-pub-5888633898042518",

   enable_page_level_ads: true

 });

</script>


函数式编程
浏览 63回答 2
2回答

蝴蝶不菲

只需将它添加到您的_Layout.cshtml文件中,在 head 标签上。

有只小跳蛙

在 razor AdsComponent 中是这样的。<h3>AdsComponent</h3><div>&nbsp; &nbsp; @Ads</div>@code {&nbsp; &nbsp; private RenderFragment Ads&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; get&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RenderFragment form = b =>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.OpenElement(0, "script");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.AddAttribute(0, "async", true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.AddAttribute(0, "src", "https://pagead2/googlesyndication.com/pagead/js/adsbygoogle.js");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.CloseElement();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.OpenElement(0, "ins");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.AddAttribute(0, "class", "adsbygoogle");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.AddAttribute(1, "style", "display:inline-block;width:728px;height:90px");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.AddAttribute(2, "data-ad-client", "ca-pub-988649660289431");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.AddAttribute(3, "data-ad-slot", "4069520508");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Test&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.AddAttribute(4, "data-adtest", "on");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.CloseElement();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.OpenElement(0, "script");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.AddContent(0, "(adsbygoogle = window.adsbygoogle || []).push({});");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.CloseElement();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return form;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP