AngularJS, ASP.NET MVC 4 and SEO
What if you want your single-page app to behave like a regular multi-page website when the client’s browser doesn’t support JavaScript? Here is an example of how to implement it with AngularJS and ASP.NET MVC:
Demo: http://angularjs-seo.tarkus.me/
Create a new ASP.NET MVC 4 project. Extract HTML from within the <body> tag of the /Views/_Layout.cshtml file into a separate layout (_BodyLayout.cshtml).
At the top of _BodyLayout.cshtml, specify the parent layout and make sure it will be set to null if the request is made with the “X-Requested-With: XMLHttpRequest” header by using Request.IsAjaxRequest()

Update the default layout name in /Views/_ViewStart.cshtml.

Add a reference to angular.js and your custom app.js files in the parent layout (_Layout.cshtml). Add <ng-view>@RenderBody()<ng-view> into _Layout.cshtml.

Add the ng-app=”App” attribute to the <html> tag and insert the following code into your app.js file with routing information:
var app = angular.module('App', []);
app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', { templateUrl: '/home/index' })
.when('/home/about', { templateUrl: '/home/about' })
.when('/home/contact', { templateUrl: '/home/contact' });
$locationProvider.html5Mode(true);
}]);
That’s it!







