But this is not compatible with Umbraco 8. I found a solution.
After creating an API controller, we need to register using IComponent.
Controller :
[PluginController("ConfigEditorManager")]
[UmbracoApplicationAuthorize(Constants.Applications.Settings)]
public class ConfigEditorController : BackOfficeNotificationsController
{
public string GetByPath(string virtualPath)
{
var data=virtualPath;
return data;
}
}
After creating controller, we need to register it using the component :
public class ConfigManagerComponent : IComponent
{
public void Initialize()
{
ServerVariablesParser.Parsing += ServerVariablesParser_Parsing;
}
private void ServerVariablesParser_Parsing(object sender, System.Collections.Generic.Dictionary<string, object> e)
{
if (HttpContext.Current == null) throw new InvalidOperationException("HttpContext is null");
if (e.ContainsKey("configManager")) return;
var urlHelper = new UrlHelper(new RequestContext(new HttpContextWrapper(HttpContext.Current), new RouteData()));
e["configManager"] = new Dictionary<string, object>
{
{"configManagerEditorsBaseUrl", urlHelper.GetUmbracoApiServiceBaseUrl<ConfigEditorController>(controller => controller.GetByPath(null))}
};
}
}
Then, this Component also needs to register in composer :
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class ConfigManagerComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.Components().Append<ConfigManagerComponent>();
}
}
Accessing your variables in angularjs :
(function () {
'use strict';
function myCustomController($scope, $http) {
var apiUrl = umbRequestHelper.getApiUrl(
"configManagerEditorsBaseUrl", "GetByPath");
console.log(apiUrl);
}
angular.module('umbraco').controller('myCustomController', myCustomController);
}
Pleased to see you got it working, yes the blog post was for v7, but it would work on v8, except replacing the ApplicationEventsHandler class with Components and Composers like you have. The important bit is the hook into the ServerVariablesParser event to add your own entry :-)
I do, at some point, need to write a v8 version of that blog post :-)
That code doesn't give you any API urls, it gives the url of a published content page. In addition it looks like it's Umbraco v7 code and not v8 code as the approach for getting Content in v8 is different.
As an FYI, it's bad practice to be creating your own UmbracoHelper instances if you can help it. For example in an API Controller there is already an Umbraco property which is a helper (assuming your controller inherits from one of the Umbraco base classes).
How can I get ApiBaseUrl or backoffice API?
How can I write or add ApiBaseUrl or backoffice API? I want to write like this :
$http.get( umbRequestHelper.getApiUrl( "configManagerEditorApiBaseUrl", "GetByPath", { virtualPath: virtualpath }))
Hey Harikrishna,
So, I think you are asking how you can get the url for a C# controller in your Angular in the back office. This blog post here: https://www.justnik.me/blog/accessing-config-settings-in-your-umbraco-angular-controller shows a way you can achieve this, but you will still have to add the Action name when you want to make that call.
Nik
Thank you, Nik For your reply.
But this is not compatible with Umbraco 8. I found a solution. After creating an API controller, we need to register using IComponent.
Controller :
After creating controller, we need to register it using the component :
Then, this Component also needs to register in composer :
Accessing your variables in angularjs :
Hi Harikrishna,
Pleased to see you got it working, yes the blog post was for v7, but it would work on v8, except replacing the ApplicationEventsHandler class with Components and Composers like you have. The important bit is the hook into the ServerVariablesParser event to add your own entry :-)
I do, at some point, need to write a v8 version of that blog post :-)
Nik
Thank you, Nik.
Hi,
Use this code in API controller
UmbracoHelper uh = new UmbracoHelper(UmbracoContext.Current);
Hi Ebin,
That code doesn't give you any API urls, it gives the url of a published content page. In addition it looks like it's Umbraco v7 code and not v8 code as the approach for getting Content in v8 is different.
As an FYI, it's bad practice to be creating your own UmbracoHelper instances if you can help it. For example in an API Controller there is already an Umbraco property which is a helper (assuming your controller inherits from one of the Umbraco base classes).
Thanks
Nik
is working on a reply...