RESTAPI ASP.NET
我创建了一个MVC项目(比如DeploymentTool)并向解决方案中添加了另一个webAPI项目(比如DeploymentToolAPI),因此这两个项目的名称空间都不同。现在我想要的是,从外部调用DeploymentToolAPI的任何HTTPPOST/HTTPGET方法,比如POSTMAN或web浏览器。我们需要为此更新WebApiConfig.cs吗? 如果没有,如何找到DeploymentToolAPI的URL。我可以调用DeploymentTool的任何方法,但在DeploymentToolAPI的情况下它都不起作用RESTAPI ASP.NET,asp.net,asp.net-mvc,asp.net-web-api,asp.net-web-api-routing,Asp.net,Asp.net Mvc,Asp.net Web Api,Asp.net Web Api Routing,我创建了一个MVC项目(比如DeploymentTool)并向解决方案中添加了另一个webAPI项目(比如DeploymentToolAPI),因此这两个项目的名称空间都不同。现在我想要的是,从外部调用DeploymentToolAPI的任何HTTPPOST/HTTPGET方法,比如POSTMAN或web浏览器。我们需要为此更新WebApiConfig.cs吗? 如果没有,如何找到DeploymentToolAPI的URL。我可以调用DeploymentTool的任何方法,但在Deploymen
routeTemplate: "api/{controller}/{id}" then your url will be like
ie. http://localhost:8526/api/ControllerName/89
如有任何帮助/建议,将不胜感激
routeTemplate: "api/{controller}/{id}" then your url will be like
ie. http://localhost:8526/api/ControllerName/89
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace StandardWebApiTemplateProject
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
routeTemplate: "api/{controller}/{id}" then your url will be like
ie. http://localhost:8526/api/ControllerName/89
routeTemplate: "api/{controller}/{id}" then your url will be like
ie. http://localhost:8526/api/ControllerName/89
若在路由模板中包含操作名称,则案例如下所示
routeTemplate: "api/{controller}/{id}" then your url will be like
ie. http://localhost:8526/api/ControllerName/89
routeTemplate: "api/{controller}/{action}/{id}" then your url will be like
ie. http://localhost:8526/api/ControllerName/ActionName/89
首先,您需要同时启动API服务和MVC web应用程序:
routeTemplate: "api/{controller}/{id}" then your url will be like
ie. http://localhost:8526/api/ControllerName/89
在Visual Studio中右键单击解决方案->属性->选择“多个启动项目:”->将两个项目的操作设置为启动:
routeTemplate: "api/{controller}/{id}" then your url will be like
ie. http://localhost:8526/api/ControllerName/89
routeTemplate: "api/{controller}/{id}" then your url will be like
ie. http://localhost:8526/api/ControllerName/89
完成后,按照@Ankush Jain发布的说明进行操作,或者从浏览器窗口复制WEB API url,因为当您在设置多个启动项目后运行项目时,您将看到您的WEB API服务和MVC WEB应用程序将在浏览器中的两个不同选项卡中打开。谢谢Ankush。你的解释给了我想要的东西。非常感谢,我明白了。谢谢你,丹尼斯。
routeTemplate: "api/{controller}/{id}" then your url will be like
ie. http://localhost:8526/api/ControllerName/89