【问题标题】:How do I specify the route in WebApi如何在 WebApi 中指定路由
【发布时间】:2017-09-12 07:37:50
【问题描述】:

如何在路由中指定如下URL格式并访问以下变量(service id、Security id、writedataflag):

 https://<Domain Name or localhost<Port No>>api/<service Id>/<security id>/<writedataflag>

【问题讨论】:

    标签: c# asp.net-web-api routing asp.net-web-api-routing


    【解决方案1】:

    配置路由模板。

    以下示例在控制器操作上使用属性路由。

    //matches GET api/<service Id>/<security id>/<writedataflag> 
    [HttpGet]
    [Route("api/{service_id}/{security_id}/{writedataflag}")]
    public IHttpActionResult MyAction(int service_id, int security_id, string writedataflag){
        //...    
    }
    

    可以更改参数类型以满足您的需要。也可以考虑使用参数约束。

    在此处了解更多信息

    Attribute Routing in ASP.NET Web API 2

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-03
      • 1970-01-01
      • 2019-12-26
      • 1970-01-01
      • 2013-04-22
      • 2013-05-12
      • 1970-01-01
      相关资源
      最近更新 更多