#Controller not exposed on Production, works in development

1 messages · Page 1 of 1 (latest)

drowsy sable
#

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:
`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:
`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.

#

Controller not exposed on Production, works in development

past onyx
#

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.

blissful cave
#

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.

drowsy sable
#

@blissful cave you mean UmbracoApiController? Isn't that going away in v15?

haughty glade
#

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.

drowsy sable
#

@haughty glade what exactly did you use? True or false?

haughty glade
#

Welcome @drowsy sable , 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.

tired ivy
#

@drowsy sable 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

GitHub

The official Umbraco Documentation. Contribute to umbraco/UmbracoDocs development by creating an account on GitHub.

drowsy sable
#

@tired ivy 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.

tired ivy
#

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?

drowsy sable
#

Well, build with only: dotnet publish -c Release fixed the issue.

seems like it doesn't like -r: linux-x64 --self-contained