Controller not exposed on Production, works in development
b
I have a weird issue with Umbraco and ControllerBase, I have two controllers, both of them work in VS debug, but I get 404 when deployed to Linux Ubuntu Production. This one doesn't work:
Copy code
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;

namespace Project.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class ExtractorController : ControllerBase
    {
        private readonly IMediaService _mediaService;


        public ExtractorController(
            IMediaService mediaService
            )
        {
            _mediaService = mediaService;
        }

        [HttpPost("extract")]
        public async Task<IActionResult> ExtractTextAndSaveImage([FromBody] ExtractRequestModel model)
This one does:
Copy code
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Models;



namespace Project.Controllers
{
    [ApiController]
    [Route("api/objava")]
    public class ObjavaController : ControllerBase
    {
        private readonly IContentService _contentService;


    
        public ObjavaController(
            IContentService contentService,
        {
            _contentService = contentService;
        }

        [HttpPost("create")]
        public async Task<IActionResult> CreateObjavaAsync([FromBody] ObjavaModel model)
Tried everything to make it work, changed naming, and still no luck.
c
As I develop on Linux all the time, just check your casing for the names and calls. MS isn't your friend in this scenario as it's too forgiving.
k
Looking at our codebase, we've never inherited
ControllerBase
for Umbraco API controllers. And the official documentation doesn't seem to suggest that either, but maybe you're trying to do this completely outside Umbraco? Perhaps try using an Umbraco controller base class instead, so Umbraco will handle the request.
b
@kdx-perbol you mean UmbracoApiController? Isn't that going away in v15?
t
I meet a similar problem Today where the Umbraco dashboard package Astroboard was working locally but not in production where the solution found after using self-contained publish using CLI.
b
@Tarik what exactly did you use? True or false?
t
Welcome @Blago Culjak , I used
dotnet publish -c Release -r win-x64 -o ../dist/publish-64 --self-contained
Don't forget to set 32 / 64 based on your system.
b
@Blago Culjak based on v15 docs: https://github.com/umbraco/UmbracoDocs/blob/main/15/umbraco-cms/reference/routing/umbraco-api-controllers/README.md you should use Controller (which is mvc class) and use attributes from there. Not sure how umbraco registers nows routing but it might be just stupid as umbraco doesn register controllers created with ControllerBase
b
@bielu I have tried with Controller and ControllerBase. On same project I have 10 pieces ControllerBase that work. Spent 2 days on this thing. Then I deployed clean out Controller with just meassage saying that it works. All other controllers works, but neither new one works in my 14.3 project. Changed naming of Controller, used default routing, used custom. Still god damn thing doesn't work.
b
I never recommended using of umbraco routing, because I always had issues with it and v15 use mvc routing, so it is not even umbraco issue 🤔 but it might be broken in v14 because they didnt fully done migration?
b
Well, build with only: dotnet publish -c Release fixed the issue. seems like it doesn't like -r: linux-x64 --self-contained
b
That's not something what I would ever consider as issue, I would report it to umbraco to see if they can fix it in their routing ;p
3 Views