Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.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
C# 自定义路由未找到与请求URI匹配的HTTP资源_C#_Asp.net_Asp.net Web Api - Fatal编程技术网

C# 自定义路由未找到与请求URI匹配的HTTP资源

C# 自定义路由未找到与请求URI匹配的HTTP资源,c#,asp.net,asp.net-web-api,C#,Asp.net,Asp.net Web Api,我的控制器看起来像这样 [RoutePrefix("api/foo")] public class CustomUserHintsController : ApiController { private ApplicationDbContext db = new ApplicationDbContext(); [HttpPost] [Route("bar")] public async Task<IHttpActionResult> GetUser

我的控制器看起来像这样

 [RoutePrefix("api/foo")]
public class CustomUserHintsController : ApiController
{
    private ApplicationDbContext db = new ApplicationDbContext();

    [HttpPost]
    [Route("bar")]
    public async Task<IHttpActionResult> GetUserHints(string Id)
    {

 ..................
 public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        // Web API configuration and services
        // Configure Web API to use only bearer token authentication.
        config.SuppressDefaultHostAuthentication();
        config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

        // Web API routes
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }

        );

        // Enforce HTTPS
        config.Filters.Add(new LocalAccountsApp.Filters.RequireHttpsAttribute());
    }
}
我做错了什么

 https://localhost:SOMEPORTNUMBER/api/foo/bar
返回一个错误

我查过好几篇这样的帖子

编辑:Global.asax.cs看起来像这样,我的应用程序中没有MVC关键字

public class WebApiApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        GlobalConfiguration.Configure(WebApiConfig.Register);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }
  }

当我传入Id时,我得到404-您正在查找的资源已被删除

根据注释,您缺少Id


test

当您测试该URL时,是否按照函数属性的要求使用POST协议?@LouisIngenthron是的,我正在使用Postman测试我的后端使用Postman并不意味着您正在使用HTTP动词POST。如果您没有更改它,Postman中的默认值是GETOkay,您是否在Postman测试中包含Id参数?@Crowcoder我将Postman更改为使用POST和PUT,只是为了检查我的后端何时被击中。这绝对是帖子