In many cases custom widgets need to get and display some items from the Sitefinity CMS backend. Use this sample to create a widget that consumes data from Sitefinity CMS. This sample works with the IRestClient to access data from Sitefinity CMS.
This sample works with a news, but you can work with other types of content from Sitefinity CMS, such as content blocks, blogs, blog posts, media, and dynamic items, etc. The WebServicePath configuration in the Renderer’s the appsettings.json controls which service the client work with.
WebServicePath
appsettings.json
NOTE: The instructions in this sample use Visual Studio 2022 and a Sitefinity renderer project named Renderer.
You can restrict the web service in Sitefinity CMS to deny access to other clients except for the Renderer. You do this by creating an API key for the service in Sitefinity CMS and then adding the same key in the appsettings.json file of the Renderer in the following way:
With this configuration, when API calls are made to the OData service under the api/default route, a special header will be passed carrying this API key and allowing the call through. This does not authenticate the call, and the user is still left anonymous.
Under your Renderer project, you must create the following folders:
Dto
ViewComponents
Views
Shared
Components
SitefinityData
ViewComponent
View
Views/Shared/Components/SitefinityData
Build your solution.
When you open your Renderer application and open the New editor, you will see the SitefinityDta widget in the widget selector. When you add the widget on your page, you can see News items displayed from Sitefinity CMS.
Renderer
This sample is available in Sitefinity’s GitHub repository. You can run and play with it. To do this, perform the following:
sitefinity-aspnetcore-mvc-samples-master/src/sitefinity-data
sitefinity-data.sln
“Sitefinity”
“Url”
sitefinity-data
Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.
This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.
This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important