我使用局部 View 在我的 MVC4 .net Web 应用程序中显示任何 Adsense 广告。当我将它从旧脚本更改为新的异步版本时,我读到来自 google 的引用脚本只需要包含一次。由于我将脚本包含在可能在一个页面中多次引用的部分 View 中,我想简单地首先包含部分包含对脚本的引用,但任何其他包含来跳过脚本引用.
有没有一种“最好的”方法可以从部分内部做到这一点?
最佳答案
到目前为止,这有效,也许还有更好的方法?
@if(Context.Items["IncludedAdsenseScript"] == null){
//include script here
// ...
//set the context item so further access will not include the script reference
Context.Items["IncludedAdsenseScript"] = true;
}
关于asp.net-mvc - 异步 Adsense 脚本 - MVC .Net 部分 View - 仅包含脚本一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18367658/