Repository navigation
Expand file tree
/
Copy pathHomeController.cs
More file actions
47 lines (41 loc) · 2.25 KB
/
Copy pathHomeController.cs
File metadata and controls
47 lines (41 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Asp2017.Server.Helpers;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
namespace AspCoreServer.Controllers
{
public class HomeController : Controller {
protected readonly IHostingEnvironment HostingEnvironment;
public HomeController(IHostingEnvironment hostingEnv) => this.HostingEnvironment = hostingEnv;
[HttpGet]
public async Task<IActionResult> Index () {
var prerenderResult = await this.Request.BuildPrerender ();
this.ViewData["SpaHtml"] = prerenderResult.Html; // our <app-root /> from Angular
this.ViewData["Title"] = prerenderResult.Globals["title"]; // set our <title> from Angular
this.ViewData["Styles"] = prerenderResult.Globals["styles"]; // put styles in the correct place
this.ViewData["Scripts"] = prerenderResult.Globals["scripts"]; // scripts (that were in our header)
this.ViewData["Meta"] = prerenderResult.Globals["meta"]; // set our <meta> SEO tags
this.ViewData["Links"] = prerenderResult.Globals["links"]; // set our <link rel="canonical"> etc SEO tags
this.ViewData["TransferData"] = prerenderResult.Globals["transferData"]; // our transfer data set to window.TRANSFER_CACHE = {};
if (!this.HostingEnvironment.IsDevelopment ()) {
this.ViewData["ServiceWorker"] = "<script>'serviceWorker'in navigator&&navigator.serviceWorker.register('/serviceworker')</script>";
}
return View ();
}
[HttpGet]
[Route("sitemap.xml")]
public IActionResult SitemapXml() => Content($@"<?xml version=""1.0"" encoding=""utf-8""?>
<urlset xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"">
<url>
<loc>http://localhost:4251/home</loc>
<lastmod>{ DateTime.Now.ToString("yyyy-MM-dd")}</lastmod>
</url>
<url>
<loc>http://localhost:4251/counter</loc>
<lastmod>{DateTime.Now.ToString("yyyy-MM-dd")}</lastmod>
</url>
</urlset>", "text/xml");
public IActionResult Error() => View();
}
}