JN
03/21/2024, 4:06 PMIan Robinson
03/21/2024, 4:57 PMJN
03/22/2024, 1:31 PM[Route("wcs/users")]
[ApiController]
public class WCSUsersController : ControllerBase
{
[HttpGet]
public ActionResult Users_Get(int pageNumber, int perPage){}
[HttpGet("{email}")]
public ActionResult User_Get(string email){}
}
JN
03/22/2024, 1:33 PMSebastiaan
03/22/2024, 1:35 PMUmbracoContext
. This is because UmbracoContext
usually only exists in a http request context.Sebastiaan
03/22/2024, 1:36 PMbackgroundScope
- https://cultiv.nl/blog/using-hangfire-to-update-umbraco-content/JN
03/22/2024, 1:39 PMSebastiaan
03/22/2024, 1:43 PMUsers_Get(int pageNumber, int perPage)
method look like?JN
03/22/2024, 1:46 PMSebastiaan
03/22/2024, 1:48 PMUmbracoContext
depending on what your doing. Comment out all of the code in that method to see if the route works, if it does, you'll probably need to ensure a context as linked abovedJN
03/22/2024, 1:52 PMSebastiaan
03/22/2024, 1:53 PMdetail
say?JN
03/22/2024, 1:55 PM{
"type": "https://tools.ietf.org/html/rfc9110#section-15.6.1",
"title": "System.InvalidOperationException",
"status": 500,
"detail": "Wasn't able to get an UmbracoContext",
"traceId": "00-81dff01760e4d72a7750b50f1019d1a9-be63e205d11557b4-00",
"exception": {
"ValueKind": 1
}
}
JN
03/22/2024, 1:55 PMJN
03/22/2024, 1:56 PMSebastiaan
03/22/2024, 1:58 PMJN
03/22/2024, 2:03 PMSebastiaan
03/22/2024, 2:06 PMcsharp
[Route("wcs/users")]
[ApiController]
public class WCSUsersController : ControllerBase
{
[HttpGet]
public ActionResult Users_Get(int pageNumber, int perPage)
{
return Ok();
}
[HttpGet("{email}")]
public ActionResult User_Get(string email)
{
JsonResult result = new JsonResult(new { email = email });
return Ok(result);
}
}
and this is the result, seems to work?
https://cdn.discordapp.com/attachments/1220403261584965864/1220735416525656175/image.png?ex=66100573&is=65fd9073&hm=c044ba469fbb5f11d274b17e6cdc01429aaa8f8b0da833511cfb9b881623d9e3&Sebastiaan
03/22/2024, 2:12 PMcsharp
[Route("wcs/users")]
[ApiController]
public class WCSUsersController : ControllerBase
{
private readonly IMemberService _memberService;
public WCSUsersController(IMemberService memberService)
{
_memberService = memberService;
}
[HttpGet]
public ActionResult Users_Get(int pageNumber, int perPage)
{
return Ok();
}
[HttpGet("{email}")]
public ActionResult User_Get(string email)
{
var member = _memberService.GetByEmail(email);
JsonResult result;
if (member != null)
{
result = new JsonResult(new { id = member.Id });
}
else
{
result = new JsonResult(new { email = email });
}
return Ok(result);
}
}
https://cdn.discordapp.com/attachments/1220403261584965864/1220736983442128916/image.png?ex=661006e9&is=65fd91e9&hm=6d1f65115beada9e7b8a1b2900acddb82507f32be919be48bc939e6700470a96&JN
03/22/2024, 2:20 PMJN
03/22/2024, 2:20 PMJN
03/22/2024, 2:21 PMSebastiaan
03/22/2024, 2:35 PMJN
03/22/2024, 2:41 PMJN
03/22/2024, 5:07 PMwcs/users/{email} (User_Get action)
error on _memberManager.AsPublishedMember(memberByEmail)
, but wcs/users (User_Gets action)
did not error on _memberManager.AsPublishedMember(memberByEmail)
, they both load custom properties from Umbraco.