【发布时间】:2017-08-29 11:06:35
【问题描述】:
我对 Asp.Net core 1 中的路由感到困惑,我需要帮助。 在 startup.cs 我有这个配置
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
我创建了一个控制器“实体”和一个方法“获取”
[Authorize]
public class EntitiesController : Controller
{
[Produces("text/html")]
public string Get(string entity, string type)
{
return "<html><body>test</body></html>";
}
}
所以,当我在下面的 url 链接中发短信时
http://localhost:12895/Entities/Get?entity=entity&type=type
以及使用参数调用的函数。
但我想更改此网址并保持相同的功能。 我希望我的网址变成
http://localhost:12895/Entities/entity?type=type
所以,只有type 将是参数,并且entity 的名称将例如更改
http://localhost:12895/Entities/human?type=type
http://localhost:12895/Entities/dog?type=type
但调用相同的函数。
这可能吗?
【问题讨论】:
标签: c# asp.net-core routing