Wednesday, December 14, 2022

How to relate custom pagetype to cms_Document?


SELECT DocumentName,NodeAliasPath,name,Link,custom_property.region,Photo from View_CMS_Tree_Joined

JOIN CONTENT_Article on DocumentForeignKeyValue = ArticleID and ClassName ='custom.property'

where ##where## Order by ##orderby##

Monday, August 29, 2022

Create sitemap in kentico 13

using Business.Services;

using Core.Configuration;

using Microsoft.AspNetCore.Mvc;

using Microsoft.Extensions.Localization;

using Microsoft.Extensions.Logging;

using Microsoft.Extensions.Options;

using SimpleMvcSitemap;

using System;

using System.Collections.Generic;

using XperienceAdapter.Localization;


namespace ABC.Controllers

{

    [Route("googlesitemap.xml", Name = "GoogleSitemap")]

    public class GoogleSitemapController : BaseController

    {

        private readonly ISitemapServices _sitemapServices;


        public GoogleSitemapController(ILogger<BaseController> logger,

            IOptionsMonitor<XperienceOptions> optionsMonitor,

            IStringLocalizer<SharedResource> stringLocalizer,

            ISitemapServices sitemapServices) : base(logger, optionsMonitor, stringLocalizer)

        {

            _sitemapServices = sitemapServices ?? throw new ArgumentNullException(nameof(sitemapServices));

        }


        public IActionResult Index()

        {


            var contentMultiple = _sitemapServices.GetContentAsync(

                       _optionsMonitor.CurrentValue.CacheInSeconds,

                       null

                       );


            List<SitemapNode> nodes = new List<SitemapNode>();


            foreach (var doc in contentMultiple.Result)

            {

                nodes.Add(new SitemapNode(doc.NodeAliasPath)

                {

                    LastModificationDate = (doc.DocumentModifiedWhen.Date)

                });

            }


            return new SitemapProvider().CreateSitemap(new SitemapModel(nodes));

        }

    }

}

Saturday, July 16, 2022

Robots.txt in .net core

 You can use middleware for creating robots.txt in .net core, 

Here is my code for robots.txt

Code:-

Installed Nuget package

PM> Install-Package RobotsTxtCore

In  startup.cs


  public void ConfigureServices(IServiceCollection services)

        {

            services.AddStaticRobotsTxt(builder =>

            builder

                .AddSection(section =>

                    section

                        .AddUserAgent("*")

                        .Allow("/")

                    )

                .AddSitemap(SiteContext.CurrentSite.SitePresentationURL + "googlesitemap.xml")

                );

}


 public void Configure(IApplicationBuilder app)

   {

        app.UseRobotsTxt();

 }

How to relate custom pagetype to cms_Document?

SELECT DocumentName,NodeAliasPath,name,Link,custom_property.region,Photo from View_CMS_Tree_Joined JOIN CONTENT_Article on DocumentForeignKe...