简体   繁体   English

如何在WebApi中指定路由

[英]How do I specify the route in WebApi

如何在路由中指定以下URL格式,并在以下位置访问变量(服务ID,安全ID,writedataflag):

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

Configure the route template. 配置路由模板。

The following example uses Attribute Routing on a controller action. 以下示例在控制器操作上使用属性路由。

//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){
    //...    
}

the parameter types can be changed to suit your needs. 可以更改参数类型以适合您的需求。 Also consider using parameter constraints. 还可以考虑使用参数约束。

Read more about that here 在这里阅读更多关于

Attribute Routing in ASP.NET Web API 2 ASP.NET Web API 2中的属性路由

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用路由名称获取WebAPI路由网址 - How to I get the WebAPI Route Url using the Route Name 如何使用visual studio WebAPI项目将外部API URL +凭据路由到我的localhost URL? - How do i route external API URL + credentials into my localhost URL using visual studio WebAPI project? 如何使用WebApi和属性路由在控制器上获取默认路由? - How do I get a default route on a controller using WebApi & Attribute Routing? 如何为将字符串数组作为参数的 .Net Core 3.1 webapi 服务调用定义路由? - How do I define the Route for a .Net Core 3.1 webapi service call which takes an array of strings as a parameter? 指定适当的路由来调用WebApi 2 Controller方法 - Specify proper route to call a WebApi 2 Controller method 如何为webapi配置此路由? - how to configure this route for webapi? 如何在 WebApi 中在控制器类级别继承路由前缀? - How do you inherit route prefixes at the controller class level in WebApi? 如何为路由参数错误指定类型转换错误消息? (C#,WebAPI) - How to specify type cast error message for route param error? (C#, WebApi) 如何获取Webapi对象列表? - How do I get a list of webapi objects? 如何在WebAPI PUT中传递对象? - How do I pass an object in a WebAPI PUT?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM