从后台调用 UmbracoAuthorizedApiController 时出现 401-Unauthorized
401-Unauthorized when calling UmbracoAuthorizedApiController from backoffice
问题
当我将我的控制器更改为 继承自 UmbracoAuthorizedApiController 而不是 UmbracoApiController 我将得到 401-Unauthorized 并且我将被重定向登录页面。
模式详情
我想从 back-office 调用我的一些后端 Api,为此我已经按照文章 in our.umbraco.
进行操作
首先,我实现了一个继承自 UmbracoApiController 的控制器,以便能够从 postman 调用我的服务。一切顺利,我可以调用我的代码并从 Umbraco 读取数据:
[RoutePrefix("api/admins")]
public class AdminsController : UmbracoApiController
{
[HttpGet]
[Route("getdata")]
public DataViewModel GetData(string id)
{
....
}
}
然后我使用插件
在仪表板中从 JavaScript 调用了我的服务
$http.get(vm.baseUrl + '/getdata?id=' + id, {})
.then(function (response) {....}
一切正常,我可以看到我的 cookie(包含令牌)已在请求中发送 headers。
然后我更新了我的控制器以继承自 UmbracoAuthorizedApiController,现在我无法访问我的 Api。
控制器现在是这样的:
[RoutePrefix("api/admins")]
public class AdminsController : UmbracoAuthorizedApiController
我做错了什么?
授权控制器(与 Umbraco 中其他包装的 MVC 控制器相同)被自动路由。当 /umbraco/backoffice/ 路径将出现在路由中时,后台授权将起作用。
检查:https://our.umbraco.org/documentation/reference/routing/Authorized/
和:https://our.umbraco.org/documentation/reference/routing/webapi/authorization
直接说:
In order for Umbraco to authentication a request for the back office,
the routing needs to be specific. Any URL that routes to :
/umbraco/backoffice/*
will be authenticated. If you have a controller
that is not routed within the prefix, it will not be authenticated for
back office use.
问题
当我将我的控制器更改为 继承自 UmbracoAuthorizedApiController 而不是 UmbracoApiController 我将得到 401-Unauthorized 并且我将被重定向登录页面。
模式详情
我想从 back-office 调用我的一些后端 Api,为此我已经按照文章 in our.umbraco.
进行操作首先,我实现了一个继承自 UmbracoApiController 的控制器,以便能够从 postman 调用我的服务。一切顺利,我可以调用我的代码并从 Umbraco 读取数据:
[RoutePrefix("api/admins")]
public class AdminsController : UmbracoApiController
{
[HttpGet]
[Route("getdata")]
public DataViewModel GetData(string id)
{
....
}
}
然后我使用插件
在仪表板中从 JavaScript 调用了我的服务 $http.get(vm.baseUrl + '/getdata?id=' + id, {})
.then(function (response) {....}
一切正常,我可以看到我的 cookie(包含令牌)已在请求中发送 headers。
然后我更新了我的控制器以继承自 UmbracoAuthorizedApiController,现在我无法访问我的 Api。
控制器现在是这样的:
[RoutePrefix("api/admins")]
public class AdminsController : UmbracoAuthorizedApiController
我做错了什么?
授权控制器(与 Umbraco 中其他包装的 MVC 控制器相同)被自动路由。当 /umbraco/backoffice/ 路径将出现在路由中时,后台授权将起作用。
检查:https://our.umbraco.org/documentation/reference/routing/Authorized/ 和:https://our.umbraco.org/documentation/reference/routing/webapi/authorization
直接说:
In order for Umbraco to authentication a request for the back office, the routing needs to be specific. Any URL that routes to :
/umbraco/backoffice/*
will be authenticated. If you have a controller that is not routed within the prefix, it will not be authenticated for back office use.