本文介绍了如何在 ASP.NET Core 中设置启动路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 ASP.NET 核心应用启动路径设置为:

/api/values

我想把这个启动路径改成:

/

查看文档中有很多关于路由约束的规范,但我不确定我是否看到如何设置在启动时运行的路由...

它在启动时调用了错误的控制器.如果我移除控制器 (ValueController),我会得到 404.它在哪里指定在运行时使用这个控制器?

我在隐藏的 launchSettings.json 中看到了希望,但正在编辑

http://localhost:5000/api/value

http://localhost:5000/

没有帮助

解决方案

Adam Weitzman 是对的,但您也可以使用 Visual Studio 的 GUI 进行切换.

  1. 在解决方案资源管理器中右键单击项目
  2. 点击属性
  3. 转到调试选项卡
  4. 选中Launch URL 复选框并设置所需的 URL.将文本框留空以启动根 URL

My ASP.NET core app startup route is set as:

/api/values

I want to change this startup route to be:

/

Looking through the documentation there is lots of specification on route constraints but I'm not sure I see how to set the route that gets run on startup...

It's calling the wrong controller on startup. If I remove the controller (ValueController), I get a 404. Where is it specified to use this controller at runtime?

I'm seeing hope in the hidden launchSettings.json but editing

http://localhost:5000/api/value

to

http://localhost:5000/

does not help

解决方案

Adam Weitzman is right, but you can also switch it using Visual Studio's GUI.

  1. Right-click on project in Solution Explorer
  2. Click Properties
  3. Go to Debug tab
  4. Check the Launch URL checkbox and set the URL you want. Leave the text box empty to launch the root URL

这篇关于如何在 ASP.NET Core 中设置启动路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 00:55
查看更多