【问题标题】:How to add SurfaceController URL to Umbraco Server Variables to access from custom Umbraco DataType in Umbraco 9如何将 SurfaceController URL 添加到 Umbraco 服务器变量以从 Umbraco 9 中的自定义 Umbraco DataType 访问
【发布时间】:2021-10-12 13:54:17
【问题描述】:
我正在将自定义 DataType 的代码从 U8 移植到 U9。
此 DataType 正在调用 Surface 控制器以检索一些数据。
在 Umbraco v 版本中,我从“Umbraco.Sys.ServerVariables”访问 URL,例如:
var apiUrl = Umbraco.Sys.ServerVariables['MainKey']['Controller1URL'];
我们在项目启动时在事件ServerVariablesParser.Parsing 上将值设置为该变量,例如:
// https://our.umbraco.com/documentation/extending/version7-assets
公共类 BackofficeControllersURLListRegistrator : IComponent
{
公共无效初始化()
{
Umbraco.Web.JavaScript.ServerVariablesParser.Parsing += ServerVariablesParser_Parsing;
}
private void ServerVariablesParser_Parsing(object sender, Dictionary
e)
{
if (HttpContext.Current == null) throw new InvalidOperationException("HttpContext is null.");
var backofficseUrls = new Dictionary();
var url = new System.Web.Mvc.UrlHelper(new RequestContext(new HttpContextWrapper(HttpContext.Current), new RouteData()));
backofficeseUrls.Add(
"Controller1URL", url.GetUmbracoApiService(controller => controller.TestFunction())
);
e.Add("MainKey", backofficeseUrls);
}
公共无效终止()
{
}
}
我们如何在 Umbraco 9 中连接到 ServerVariablesParser Notification(如果存在)以及如何检索 Controller 函数 URL,以便我可以像以前版本一样在 DataType JS 代码中检索它?
问题是针对 umbraco9,但我无法创建新标签...
【问题讨论】:
标签:
.net-core
asp.net-core-mvc
umbraco
.net-5