[英]Routes that starts with the same prefix as controller not working
Why Routes that starts with the same prefix as controller not working? 为什么以与控制器相同的前缀开头的路由不起作用? With below code on my controller I am making a get call where RoutePrefix is same as the controller name.
在控制器上使用以下代码,我进行了一次get调用,其中RoutePrefix与控制器名称相同。 Now I am making a call as something like http://[localhost]/subscribers which is not working.
现在,我正在拨打类似http:// [localhost] / subscribers之类的电话,但该电话无法正常工作。
namespace WebApi.Controllers
{
[RoutePrefix("subscribers")]
public class SubscribersController : ApiController
{
[Route("")]
[HttpGet]
public IQueryable<string> Get()
{
return new string[] { "value1", "value2" }.AsQueryable();
}
}
}
I tried something as Route("~/subscribers") instead of just Route("") but that is not working as well. 我尝试了一些类似Route(“〜/ subscribers”)的方法,而不仅仅是Route(“”),但是效果不佳。
The option that is working for me currently is http://[localhost]/subscribers/all with below code 当前对我有用的选项是http:// [localhost] / subscribers / all,其中包含以下代码
namespace WebApi.Controllers
{
[RoutePrefix("subscribers")]
public class SubscribersController : ApiController
{
[Route("all")]
[HttpGet]
public IQueryable<string> Get()
{
return new string[] { "value1", "value2" }.AsQueryable();
}
}
}
How can I make it work as http://[localhost]/subscribers 我怎样才能使它作为http:// [localhost] / subscribers
Both samples work just fine. 两个样本都很好。 I've created a new web project and added both versions to the project.
我创建了一个新的Web项目,并将两个版本都添加到了该项目中。 Try to create a sample project and check if problem persists.
尝试创建一个示例项目,并检查问题是否仍然存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.