Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.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中间使用get参数的WebApi_C#_Asp.net Web Api_Routes - Fatal编程技术网

C# 在uri中间使用get参数的WebApi

C# 在uri中间使用get参数的WebApi,c#,asp.net-web-api,routes,C#,Asp.net Web Api,Routes,您好,有点新手-使用VS 2013 ASP.net WebApi-具有以下uri的规范: /device/{deviceId}/register 尝试了以下几种方法: public class DeviceController : ApiController { [Route("/{deviceId}/register")] [HttpGet] public async Task<IHttpActionResult> Register

您好,有点新手-使用VS 2013 ASP.net WebApi-具有以下uri的规范:

/device/{deviceId}/register
尝试了以下几种方法:

public class DeviceController : ApiController
{
        [Route("/{deviceId}/register")]
        [HttpGet]
        public async Task<IHttpActionResult> Register(string deviceId)
        {
        }
}

您应该将路由属性调用更改为:

[Route("device/{deviceId}/register")]
并删除您在RouteConfig.RegisterRoutes中所做的所有更改—它们不是必需的

那它就可以正常工作了。属性路由与HttpConfiguration对象中定义的路由无关。

请尝试
[Route(“device/{deviceId}/register”)]
。属性路由和显式配置路由彼此独立。
[Route("device/{deviceId}/register")]