• Deleting old content versions using the API

    Description Sometimes the episerver configuration attribute uiMaxVersions does not work, it is instead possible to use IContentVersionRepository to delete older content versions.  Resolution The example below is only for one content item. The code could be developed further to loop through the entire content tree - this code could be run for example in a scheduled job. Note that the user who runs the job would need to have delete permissions.Remember to back up your database b...

  • Enable special characters in URL Segment

    Description There's a default validation for URL Segment when a page is created which replaces special characters with the normal ones (for example ä becomes “a”). In some cases, clients want to keep those special characters in the URLs for their non-English versions of the web site. Resolution Create a custom UrlSegment module which overrides the default URL validation. Here's an example (UrlSegmentConfigurationModule.cs): After that add the following key to the appSettings ...

  • How to stop a custom job in Admin UI in case your job has a loop.

    Description There are some partner developers followed this article http://world.episerver.com/documentation/developer-guides/CMS/scheduled-jobs/  to stop a job in admin UI. According to this post, a basic scheduled with the possibility to stop a job by overriding Stop method, so this method is called when a user clicks on Stop button. using System; using EPiServer.Core; using EPiServer.PlugIn; using EPiServer.Scheduler; namespace MyEpiserverSite.Jobs { [ScheduledPlugIn(DisplayName...

  • How to filter out expired content in Episerver Search

    Description This article contains a sample that explicitly will exclude expired content in Episerver Search results. Resolution private bool IsPublished(IVersionable content){ if (content == null) return true; if (content.StopPublish > DateTime.UtcNow) return content.Status.HasFlag(VersionStatus.Published); return false; }

  • Import Data not updating properties

    Description When updating a value for a property and then overwriting that value with an import data file, the property value does not change back to the original value during the import. Steps: 1. Export data with content type for example an Image File for All Site Data folder. 2. Modify the Copyright for an image file 3. Import data into the All Site Data folder. The problem is the property value does not change back to the original value during the import. After selecting the Upload ...

  • Using CultureSpecific attributes on MediaData

    Description When using culture specific attributes for properties connected to MediaData classes, such as our implementation of ImageData, the text that is added in the properties is not being handled as culture specific. Text saved on the Swedish site overrides text from the Norwegian site and vice versa. Resolution Unfortunately, localizing media assets is not supported yet but the following workarounds should work in this case https://gregwiechec.com/2015/07/localizable-med...

  • Resources to Create a Controller in Alloy

    Description This article provides additional resources and samples for adding an MVC controller to the Alloy Demo site. Resolution Get started developing with CMS - Requires some basic knowledge of building .net websitesEpiserver CMS 9 tutorial with asp.net - tutorial with MVC 5 and bootstrapEpiserver CMS 9 documentation  - General documentationIntroducing Alloy Demo KitAlloyDemoKit Repo  - A github project with additional features and demos.

  • Count of user in role is always 0

    Description The count of user in role is always 0 even when we have users  Resolution This happened in case we have a custom SecurityEntityProvider, we missed to override the FindUsersInRole method in own custom SecurityEntityProvider class to set the totalCount parameter (count of the user in role). By default, it set totalCount = 0 that why we alway see 0 even when we have users  public virtual IEnumerable<string> FindUsersInRole(string roleName, string usernameToMatch...

  • Commerce CheckMultiWarehouse implementation

    Description This article covers implementing multi-warehouse logic as described here: https://world.episerver.com/documentation/developer-guides/commerce/warehouses-and-inventories/Multi-warehouse-implementations/  In the paragraph "Disable the lockout“ – there is a recommendation to replace the existing method CheckMultiWarehouse. When overriding the CheckMultiWarehouse it is never called. It still uses the OrderGroupActivityBase class not the custom class. Because OrderGroupActiv...

  • TemplateCoordinator: Cannot register multiple partial views for model type

    Description This article describes an issue with registering multiple views for a model type. Step to reproduce Register 2 partial views for the same model type (see TemplateCoordinator in Alloy). Expected: Both templates are registered.Actual: Only the first template is registered. //Returns 4 templates in Alloy on 10.10.4 (includes both PagePartial and PagePartialWide) //Returns 3 templates in Alloy on 11.1.0 (PagePartialWide missing) var r = ServiceLocator.Current.GetInstance(); var...

  • SearchPhaseExecutionException[Failed to execute phase [query]

    Description This articles describes an error that can happen when calling a search. For example when calling: var query = SearchClient.Instance.Search().FilterForVisitor().HistogramFacetFor(x => x.StartPublish.Value , DateInterval.Year); the following error would appear. The remote server returned an error: (400) Bad Request. SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[04E6LChKQ0GFPQJBStIZog][armahe_phoenixdevindex][1]: RemoteTra...

  • Create user with same email ID in the solution base on AspNetIdentity

    Description How to create one user who can register to multiple sites with same email ID. The default implementation in QuickSilver site is restricts this as it checks the uniqueness of the Email id of the user.  Resolution In UserService.cs file of QuickSilver project, you can configure validation logic and set RequireUniqueEmail = false in the constructor method. This is responsible for creating user actually checks the uniqueness of the Email id of the user.    

  • How to inject ILogger to container from CMS 11

    Description In the Breaking Changes in CMS 11, it is no longer supported to get an ILogger instance from the IOC container. But if your solution  Resolution There is an alternative way is using LogManager to get ILogger Instance https://world.episerver.com/documentation/developer-guides/CMS/logging/ But if you've recently upgrade your solution to CMS 11 and there is a lot of code using injected ILogger from IoC container. You don't want to change this, let use the below code  ...

  • Error CS0619 'ServiceConfigurationContext.Container' is obsolete

    Description This article describes an issue with the ServiceConfigurationContext.Container method after having upgraded to Episerver 10+.  The API will throw the following error. Error CS0619'ServiceConfigurationContext.Container' is obsolete: 'Access StructureMap using extension method StructureMap() available in NuGet package EPiServer.ServiceLocation.StructureMap' The discussion on this issue can be seen in our documentation. New NuGet package for StructureMap integration A new NuGet...

  • Setting a default language for the HTML tag

    Description The HTML lang attribute can be used to declare the language of a Web page or a portion of a Web page. This is meant to assist search engines and browsers. According to the W3C recommendation you should declare the primary language for each Web page with the lang attribute inside the <html> tag, like this: <html lang="en">...</html> In XHTML, the language is declared inside the <html> tag as follows: <html xmlns="http://www.w3.org...

  • ContentRoute.GetValue Breaking Change in Episerver 10

    Description This article describes an issue with ContentRoute.GetValue not being available after updating to Episerver 10.  The code recommends using the IContentRoute. however that API does not have direct access to GetValue. Resolution Please see here for breaking changes in CMS 10. Breaking changesThe following classes were removed from the public API and implementation moved into sub namespace ".Internal". In cases where an implementation was exposed in another p...

  • EPiServer Find ProjectTitleFrom With Conventions.UnifiedSearchRegistry Does Not Work

    Description This article describes an issue with setting a projection using SearchClient.Instance.Conventions.UnifiedSearchRegistry. The code is examplified below SearchClient.Instance.Conventions.UnifiedSearchRegistry .ForInstanceOf() .ProjectTitleFrom(x => string.Format("{0} [{1}]",x.SearchTitle(), x.SearchFileExtension()));  For more samples please see here. Resolution The issue is identified in FIND-2625 and resolved in Episerver.Find 12.7.1 which can be foun...

  • Create node in a saved state by service API

    Description Creating(POST) a node or entry with start date publishes the node or entry on the start date. Is there a way we can have the node/entry created in just saved state rather than having it in a published state? Resolution Set IsActive=false when posting to service API var model = new Node{Code = "Node_1",Catalog = "Fashion", EndDate = DateTime.UtcNow.AddDays(100), IsActive = false,MetaClass = "FashionNode",Name = "Test",StartDat...

  • How to get direct link to page in edit mode

    Description This article describes how to get a direct link to a page in edit mode using the Episerver API. This may be useful for developing a custom report. Resolution When looking for a link like the example below http://localhost:17000/Internal/UI/CMS/?language=sv#context=epi.cms.contentdata:///43687&viewsetting=viewlanguage:///sv you can use the following code segment. PageEditing.GetEditUrl(page.ContentLink) For more information on this API please see here.

  • 'System.ArgumentNullException' occurred in Newtonsoft.Json.dll

    Description This article describes a cryptic error that can be thrown from any Episerver API and how to troubleshoot it. The complete error message can be seen below. An exception of type 'System.ArgumentNullException' occurred in Newtonsoft.Json.dll but was not handled in user codeAdditional information: The provided content link does not have a value. This issue occurs because of missing or mismatched assembly from a migration or update. Resolution Here are the steps to trou...

  • How to Return JSON for Episerver Form by Sort Order

    Description This article illustrates the code to return the JSON for an Episerver Form by a specified sort order. Resolution The code below can be found in full here. var formIden = new FormIdentity(formGuid, (content as ILocalizable).Language.Name); var friendlyNames = _formRepository.Service.GetDataFriendlyNameInfos(formIden)                       .Where(fn => !fn.ElementId.StartsWith(EPiServer.Forms.Constants.SYSTEMCOLUMN_PREFIX))                       .OrderBy(fn => fn...

  • Preview functionality outside the Episerver edit mode

    Description Episerver has preview functionality available in edit mode. It did not satisfy our customer. The customer wanted to see the page as it will be displayed when get published. But I found that Episerver has "hidden" feature which enables you to display concrete content version. Episerver's HierarchicalCatalogPartialRouter already supports the versioned content display. You just have to take a string representation of the content link which has version info and append ...

  • Get visitor group by current user

    Description Check the visitor groups that the current visitor is part of IN CODE Resolution public List<VisitorGroup> GetVisitorGroupByCurrentUser(){      List<VisitorGroup> filteredVisitorGroup = new List<VisitorGroup>();      var visitorGroupRepository = ServiceLocator.Current.GetInstance<IVisitorGroupRepository>();      var visitorGroupRoleRepository = ServiceLocator.Current.GetInstance<IVisitorGroupRoleRepository>();      var httpContextAccess...

  • Cannot programmatically set modified date

    Description Is it possible to update modified date of the page programmatically no matter when page is changed or published. When assigning "SetChangedOnPublish" as true and a date is set, when the content is updated, the current date and time are set instead of the value which was assigned.  Example:  Page X has Modified date as 21-August-2017 Now they are changing the modified date by using below code. writableNewsPage.Changed = [DATE CAN BE 01-AUGUST-2017, which they want ...

  • How To Get Page Revisions For An Episerver Page

    Description This articles provides a discussion and a sample to pull a page revision for an Episerver page. Resolution It may be necessary to retrieve certain versions of page content. The IContentRepository or IContentLocator will always return the latest version of the content. If one needs a certain revision then the API is IContentVersionRepository. There is one word of caution about IContentVersionRepository. Episerver doesn't provide any form of caching when working with...

  • Length of a LongString property makes the site down

    Description Timeout error and the following message appear when opening some pages: "Array dimensions exceeded supported range." Using SQL profiler to find that some queries takes more than 30 seconds. The actual execution time is up to 5 minutes.  exec netContentLoadLongString @LongStringGuid='1B64UIL1-13A2-4419-A10F-D12F0B2ED4F0' Looking into the indexes, some of them have high fragmentation (98 and 97%), but rebuilding them doesn't help. If you change the GUID value to anot...

  • PropertyList collection in editor not rendering when model includes CategoryList property

    Description The article describes an issue when the editor for the CategoryList property does not render at all. The Chrome network panel when rendering shows an http 500 error when viewing the All properties view for the content with the CategoryList property in the CMS editor. GET http://localhost:57262/EPiServer/shell/Stores/metadata/<custom site path>?dojo.preventCache=1495807805787 There is also an error in the site logs to coincide with the error above. System.InvalidCastExc...

  • Loop Through Languages of a Page

    Description Below is a code sample of how to loop through language versions of a page. Resolution foreach (var pageLanguage in pageTypeData.ExistingLanguages){    var repository = ServiceLocator.Current.GetInstance<IContentLoader>();    var test1 = repository.Get<PageData>(pageTypeData.ContentGuid, pageLanguage);}

  • Uncaught Reference Error: $ is not defined

    Description When not logged into EpiServer JavaScript does not seem to run and a "Uncaught Reference Error: $ is not defined" is found in the developer consul but the JavaScript runs fine when logged in. Resolution This is caused by jQuery not being loaded. When logged into EpiServer jQuery is loaded up during the page load as part of the product but when your not logged in EpiServer does not automatically load jQuery. If your code is dependent on jQuery you will nee...

  • How to add a media item via the API

    This sample illustrates how to add a media block type to the CMS. This assumes you have a Article page type but really you just need to pass in a ContentLink to the location you want to save the file to.  Resolution Below are some sample methods to add a new blob and insert data into it.  //article is a page type (used to get the content link) public string AddFile(Article article, HtmlFile file) { string url = ""; try { ...