Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core asp.net核心3路由_Asp.net Core_Asp.net Core 3.0 - Fatal编程技术网

Asp.net core asp.net核心3路由

Asp.net core asp.net核心3路由,asp.net-core,asp.net-core-3.0,Asp.net Core,Asp.net Core 3.0,在我的Asp.NETCore3项目中,我使用一些控件从js代码访问来做一些事情,同时还使用Razor页面 在“配置服务”部分: services.AddControllersWithViews(); services.AddRazorPages(); 我在视图中添加了RazorPages和MVC控制器 然后在配置部分 app.UseRouting(); app.UseEndpoints(endpoints => {

在我的Asp.NETCore3项目中,我使用一些控件从js代码访问来做一些事情,同时还使用Razor页面

在“配置服务”部分:

    services.AddControllersWithViews();
    services.AddRazorPages();
我在视图中添加了RazorPages和MVC控制器

然后在配置部分

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

        });
增加了上述代码。 当我尝试访问控制器时,我得到了404。我还尝试只添加
services.AddControllers()

我需要帮助

编辑:控制器代码

public class DashboardsController : BaseController, IDashboardsController
{
    [HttpGet]
     public async Task<JsonResult> GetAssetCategorySummaryAsync(){
        -------
    }
}
公共类DashboardsController:BaseController、IDashboardsController
{
[HttpGet]
公共异步任务GetAssetCategorySummarySync(){
-------
}
}

您的url应该是
localhost:9011/Dashboards/GetAssetCategorySummary

您可以修改Startup.cs,如下所示,以允许使用整个操作名称:

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

这是github上的一个已知问题,您可以参考。

我可以推荐我的解决方案

启动中

app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
    endpoints.MapControllers();
});
像这样创建自定义基本控制器

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

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

Rout`api/Test/Test

您正在尝试什么URL?控制器看起来像什么?获取404(未找到)这是我正在尝试的URL。控制器公共类DashboardsController:BaseController,IDashboardsController{[HttpGet]公共异步任务GetAssetCategorySummarySync(){------------}使用控制器代码更新您的问题。无法在评论中阅读。抱歉。添加控制器代码是的,我解决了这个问题。我的问题与SuppressAsyncActionNames有关,这是NetCore3中一个突破性的更改。我正在使用下面的路由,它对我来说运行良好
app.UseEndpoints(endpoints=>{endpoints.mapController();endpoints.MapControllerRoute(名称:“默认”,模式:{controller=Home}/{action=Index}/{id?}”);endpoints.MapRazorPages();             });谢谢。asp.net core 3中的另一个突破性变化我已经做到了。再次感谢你。Bu I未更改URL更改添加选项。SuppressAsyncSuffixInActionNames=false