ASP.NET Core WebAPI默认路由不起作用 [英] ASP.NET Core WebAPI default route not working

查看:774
本文介绍了ASP.NET Core WebAPI默认路由不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经遵循了几个示例,建议在ASP.NET Core WebAPI项目中设置默认路由,我需要替换

I've followed several examples suggesting that to set my default route in an ASP.NET Core WebAPI project, I need to replace

app.UseMvc();

使用

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "default",
        template: "{controller}/{action}",
        defaults: new { controller = "Traders", action = "Get" });
});

但是当我运行时,它默认为localhost:54321/api/values,并且应该默认为localhost:54321/Traders

But when I run it defaults to localhost:54321/api/values and it should default to localhost:54321/Traders

怎么了?

推荐答案

如@tmg所述,请执行以下操作:

As @tmg mentioned, do the following:

右键单击您的Web项目->选择属性->选择左侧的调试"标签->然后编辑启动网址"字段以设置您自己的默认启动URL.

Right click your web project -> Select Properties -> Select the Debug tab on the left -> Then edit the 'Launch Url' field to set your own default launch url.

这篇关于ASP.NET Core WebAPI默认路由不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆