1

In my Asp.net core 3 project I am using some controler to access from js code to do some stuff and also using Razor pages at the same time.

at the configure service section :

    services.AddControllersWithViews();
    services.AddRazorPages();

I added both RazorPages and MVC controller with view.

And at then configure section

        app.UseRouting();
        app.UseEndpoints(endpoints =>
        {              
            endpoints.MapRazorPages();
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");

        });

Added above codes. When I try to access to controller I am getting 404. I also tried to add just services.AddControllers();

need help please.

Edit : controller code

public class DashboardsController : BaseController, IDashboardsController
{
    [HttpGet]
     public async Task<JsonResult> GetAssetCategorySummaryAsync(){
        -------
    }
}
9
  • What URL are you attempting? What does the controller look like? Commented Sep 24, 2019 at 16:55
  • GET localhost:9011/Dashboards/GetAssetCategorySummaryAsync 404 (Not Found) it's the URL I am trying. and the controller public class DashboardsController : BaseController, IDashboardsController { [HttpGet] public async Task<JsonResult> GetAssetCategorySummaryAsync(){ ------- } } Commented Sep 24, 2019 at 17:49
  • 1
    Update your question with the controller code. Can't read it in a comment. Commented Sep 24, 2019 at 17:54
  • sorry. added controller code Commented Sep 24, 2019 at 18:07
  • 1
    yes I solved the issue. my problem was related to SuppressAsyncSuffixInActionNames one of breaking changes in net core 3. I am using below routing and it works fine for me app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); Commented Nov 15, 2019 at 13:14

2 Answers 2

1

Your url should be localhost:9011/Dashboards/GetAssetCategorySummary.

You could modify the Startup.cs like below to allow using the whole action name:

public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc(options =>
        {
            options.SuppressAsyncSuffixInActionNames = false;
        });
        services.AddControllersWithViews();
        services.AddRazorPages();
    }

It is a known issue on github,you could refer to here.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you. another breaking change in asp.net core 3 github.com/aspnet/Announcements/issues/351
I have already did it. thank you again. Bu I did no change the URL change adden options.SuppressAsyncSuffixInActionNames = false
0

I can recommend my solution.

In Startup

app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
    endpoints.MapControllers();
});

Create your CUSTOM base controller like that.

    [Route("api/[controller]/[action]/{id?}")]
    [ApiController]
    public class CustomBaseController : ControllerBase
    {
    }

And use CustomBaseController

 public class TestController : CustomBaseController
    {
        public IActionResult Test()
        {
            return Ok($"Test {DateTime.UtcNow}");
        }
    }

Rout` api/Test/test

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.