简体   繁体   English

带有Angular和ASP.NET MVC的SEO(非SPA)

[英]SEO With Angular and ASP.NET MVC (not SPA)

I have an hybrid architecture using ASP.NET MVC and AngularJS. 我有一个使用ASP.NET MVC和AngularJS的混合体系结构。

I use ASP.NET MVC for routing so I have not a single page application. 我使用ASP.NET MVC进行路由,所以我没有一个页面应用程序。

I inject my C# ViewModel into angular controller using init() method like this in my ASP View : 我在ASP View中使用init()方法将C#ViewModel注入角度控制器:

@model AddictLive.Core.ViewModel.Mobile.ViewModels.MovieViewModel
@using Newtonsoft.Json

<div ng-controller="MovieController" ng-init="init(@Html.Raw(JsonConvert.SerializeObject(Model)))">
     ...
</div> 

To get my ViewModel in my Angular controller I use : 要在Angular控制器中获取ViewModel,请使用:

$scope.init = function (movieViewModel) {
    $scope.property1= movieViewModel.property1;
    $scope.property2= movieViewModel.property2;
};

In this context I met an SEO problematic because pages content's are loaded dynamically by Angular even if my ViewModel is load server side. 在这种情况下,我遇到了一个SEO问题,因为即使我的ViewModel是加载服务器端,页面内容也是由Angular动态加载的。

When google bot scan my page all variables are always here ({{variable}} or ng-repeat="movie in movies"). 当Google机器人扫描我的页面时,所有变量始终都在此处({{variable}}或ng-repeat =“电影中的电影”)。

All solutions I have found on the web are based on the hashtag #! 我在网上找到的所有解决方案都基于#号标签! for single page application but my website it not a single page application. 单页应用程序,但我的网站不是单页应用程序。

I have found a solution for {{variable}} like this using : 我使用以下方法找到了{{variable}}的解决方案:

<span ng-bind="variable">@Model.myVariable</span>

but I have problem for ng-repeat and ng-include because I can't use razor @Model. 但是我对ng-repeat和ng-include有问题,因为我不能使用razor @Model。

I have read that all content under an hidden div is not a good practice for google seo so it is not an option too. 我已经读到,隐藏div下的所有内容对于Google seo都不是一种好习惯,因此也不是一种选择。

Does anyone know a solution to my problem? 有人知道我的问题的解决方案吗?

Thanks 谢谢

I have no direct solution for you but an advice. 我没有为您提供直接解决方案,但有建议。 I learned that it iis hardly possible to create sites that are good for users and search engines. 我了解到,几乎不可能创建对用户和搜索引擎有利的网站。 Topics like ajax and on-demand-loading are for users and bad for search engines and also the other way around. 诸如ajax和按需加载之类的主题面向用户,不利于搜索引擎,反之亦然。 eg so many pages have texts for search engine only that are so boring for users. 例如,如此多的页面仅具有用于搜索引擎的文本,这对于用户而言非常无聊。

I recommend to make separate landing pages with nice urls. 我建议使用漂亮的网址制作单独的目标网页。 At the top of the landing page you do something to increase your conversion, eg play a search button or whatever and below you place content for search engines. 在登录页面的顶部,您可以执行一些操作来提高转化率,例如,播放搜索按钮或执行其他操作,然后在下方放置搜索引擎的内容。 Then make your user-pages invisble for google with: 然后通过以下方法使您的用户页面对Google不可见:

<meta name="robots" content="nofollow,noindex" />

Create two different pages: One for your user and one for the search engine. 创建两个不同的页面:一个用于您的用户,一个用于搜索引擎。 This guarantees that you do not have to do any compromises. 这样可以保证您不必做任何妥协。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM