Tuesday, April 30, 2019

EPiServer, C# - Create External Content Url


 public static string ContentExternalUrl(ContentReference contentLink, CultureInfo contentLanguage, bool absoluteUrl)
        {
            var result = ServiceLocator.Current.GetInstance
<UrlResolver>().GetUrl(
                contentLink,
                contentLanguage.Name,
                new VirtualPathArguments
                {
                    ContextMode = ContextMode.Default,
                    ForceCanonical = absoluteUrl
                });


            if (absoluteUrl)
            {
                Uri relativeUri;

                if (Uri.TryCreate(result, UriKind.RelativeOrAbsolute, out relativeUri))
                {
                    if (!relativeUri.IsAbsoluteUri)
                    {
                        var siteDefinitionResolver = ServiceLocator.Current.GetInstance
 <ISiteDefinitionResolver>();
                        var siteDefinition = siteDefinitionResolver.GetByContent(contentLink, true, true);
                        var hosts = siteDefinition.GetHosts(contentLanguage, true).ToList();

                        var host = hosts.FirstOrDefault(h => h.Type == HostDefinitionType.Primary)
                            ?? hosts.FirstOrDefault(h => h.Type == HostDefinitionType.Undefined);

                        var basetUri = siteDefinition.SiteUrl;

                        if (host != null && host.Name.Equals("*") == false)
                        {
                            Uri.TryCreate(siteDefinition.SiteUrl.Scheme + "://" + host.Name, UriKind.Absolute, out basetUri);
                        }

                        var absoluteUri = new Uri(basetUri, relativeUri);

                        return absoluteUri.AbsoluteUri;
                    }
                }
            }

            return result;
        }




OR:
  public static string ExternalUrl(this ContentReference contentLink)
        {
            var locator = ServiceLocator.Current.GetInstance<IContentLoader>();
            var pd = locator.Get<PageData>(contentLink);

            var urlString = UrlResolver.Current.GetUrl(contentLink, ((ILocalizable) pd).Language.Name, new VirtualPathArguments { ForceCanonical = true });
            if (string.IsNullOrEmpty(urlString))
            {
                return urlString;
            }

            var uri = new Uri(urlString, UriKind.RelativeOrAbsolute);
            if (uri.IsAbsoluteUri)
            {
                return urlString;
            }

            if (!uri.IsAbsoluteUri)
            {
                var siteDefResolver = ServiceLocator.Current.GetInstance<ISiteDefinitionResolver>();
                SiteDefinition siteDefinition = siteDefResolver.GetByContent(
                    contentLink: contentLink,
                    fallbackToWildcard: true,
                    fallbackToEmpty: true);

                return new Uri(siteDefinition.SiteUrl, uri).ToString();
            }

            return urlString;
        }

Sunday, April 28, 2019

React - Reminders

Example Contact card

<div className="contacts">
<ContactCard
contact={{name: "Mr. Whiskerson" }} //the first curly makes the JSX context to JS the second say its an object.
name="Mr. Whiskerson"
imgUrl="http://placekitten.com/300/200"
phone="(212) 555-1234"
email="mr.whiskaz@catnap.meow"
/>

Wednesday, April 3, 2019

Chrome Console - List all href links in a page

var links=document.getElementsByTagName('a')
for (var i = 0; i<links.length; i++)

    console.log(links[i].href);
}

Friday, March 29, 2019

TFS / Nuget - Cannot build after getting latest from Source Controll

In nuget console run:

Remove the current references in project/s.

update-package -reinstall
PM> Update-Package -reinstall

also try:
PM> Get-Project –All | Add-BindingRedirect

Friday, March 15, 2019

500.19 - Http Server error

  1. Check permissions on the APP Pool User.
  2. And that the IIS Rewrite Module is installed.
  3. Also check that in add remove windows feature that the:
  4. IIS / World wide web Services / Application Development Features is checked especially aps.net 4.7

Saturday, March 9, 2019

Nuget - Nuget adds broken References without path.

I did already try Update-Package -reinstall. But this did not help.
I also removed all references manually and empied the package folder without results.

The solution:
Clear the nuget cache (don't know if this was necessary). Under tools -> Nuget Package Manager -> Nuget Settings and Clear cache.

Unload proj from solution
Edit csproj file and delete nuggets entries from csproj file (ItemGroup).
Reload proj
It works!!