给定ASP.NET Web API路由:
example/{Id}
它映射到以下ApiController操作方法:
public void Example(Model m)
{
...
}
模型类定义为:
public class Model
{
public int Id { get; set; }
public string Name { get; set; }
}
当我将JSON { "Name": "Testing" }发布到URL /example/123时,Model对象的Id属性并未绑定。它仍然是0而不是123。
如何使模
我试图找出这两个框架中URL匹配的不同之处
我知道以下对于ASP.Net Web是正确的,想知道ASP.NET内核也是这样吗?
用于在未显式指定HTTP方法的情况下派生HTTP方法的操作名称,例如
public int GetById(int Id);
这里没有指定HTTP方法,但是由于约定,它只能匹配到get请求
如果未指定HTTP方法,并且也不能从操作名称派生HTTP方法,则默认为POST
参数还参与匹配URL,如下所示
// GET / IEnumerable / GET public string[] Get() {返回新string[]{ "val
我有一个ASP.NET MVC应用程序,它正在调用ASP.NET Web服务:
public class MyClass
{
private static HttpClient client = new HttpClient();
public async Task DumpWarehouseDataIntoFile(Warehouse myData, string path, string filename) // See Warehouse class later in this post
{
try
{
我是编写RESTful web服务的新手,我想使用ASP.NET web API构建一个RESTful Web服务,第三方开发人员将使用它来访问我的应用程序的数据。
我的控制器被设计为响应以下URI:
api/warehouse --> return list of warehouses
api/warehouse/001 --> return warehouse 001
api/Binwarehouse --> return list of bins by warehouses
api/Binwarehouse/001 --> return list of bins
我是API工作的新手。我有一个使用OWIN自托管的ASP.NET Web API项目。然后,我为我的ASP.NET创建了一个单独的APIMVC5项目,包括控制器和后端工作。我在这个项目中没有视图,因为我没有需要,我只是从端点返回JSON数据。我发现我的程序的MVC控制器/路由的路由工作得更好。当最初尝试在我的Web项目中使用ApiController控制器时,我遇到了许多令人头疼的问题,试图使路由正常工作。MVC对我来说开箱即用,就像路由一样。 那么,当我从自托管的Web API项目中运行时,如何联系位于单独MVC项目中的这些控制器/路由呢?我读到过自托管MVC不起作用,所以我想找出一个变通
我正在尝试将Swashbuckle添加到我的ASP.NET MVC WebAPI项目中。我在Visual Studio 2013中使用了一个空的MVC项目模板。后来我添加了所需的文件/包等,但不知何故我无法将Swashbuckle集成到其中。每次我运行这段代码时,在SwashConfig.cs中都会出现以下错误。
以下是我的web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.
我已经创建了一个ASP.NET MVC5 web应用程序,然后添加了HelpPages和Web组件。MVC应用程序和HelpPages工作得很好,但我无法通过http://localhost:port/api/Samples/GetAll访问API Controller。什么可能是错误的,我如何解决这个问题?
WebApiConfig.cs
namespace MySolution.ApiV1
{
using System.Web.Http;
public static class WebApiConfig
{
public static void Re
我想为Web API启用属性路由,因为它看起来会使路由更容易定义。此处的示例:显示了如何在WebApiConfig.cs文件中完成此操作:
using System.Web.Http;
namespace WebApplication
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API routes
config.MapHttpAttribut
我被这事搞疯了。
我正在用VisualStudio2012Premium、.NET Framework4.5.1和C#开发一个WebApi2.2项目。
我创建了一个空的ASP.NET MVC 5项目。我删除了Global.asax并创建了这个Startup.cs类:
using Microsoft.Owin;
using Ninject;
using Ninject.Web.Common.OwinHost;
using Ninject.Web.WebApi.OwinHost;
using Owin;
using System.Reflection;
using System.Web.Http;
我使用OWIN来自宿主(我不使用IIS),我的web,我读了很多关于基于asp.net、web和angularJS的web应用程序的文章。在大多数示例中,api的默认路由如下
HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(_baseAddress);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = R
在我的ASP.NET Web (ASP.NET 4MVC5)应用程序中,我有两个路由配置如下:
// Default route. Comes "out of the box" with Web Api.
// e.g. api/users/123
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
def
我记得在HTTP中,用ASP.NET命令(例如GetList() => HTTP GET,Delete() => HTTP DELETE)作为Web API REST方法名称的前缀就足以让传入的调用得到适当的路由。 我还记得,在ASP.NET Web API中,会进行参数匹配,这样即使是Get(int id)和Get(int id, string name)也可以自动适当地路由,而不需要任何属性。 public class MyController
{
public ActionResult Get(int id) => ...
public ActionResu
我正在创建一个ASP.NET网络API,它从一个dll文件中调用一个加法函数,并找到用户在该URL中输入的数字之和。例如:http://localhost:52241/api/dlladdition/9/6 (用户输入编号9和6)。结果将是15。我希望结果类似于{ "result" : 15 }。我怎样才能做到这一点?
这是我的代码:
dll文件
Mathclass.cs
public static class MathClass
{
//method for Addition
public static int Add(int num1, int num2)
我一直在为基于属性路由的WebApi2设置而奋斗,我已经没有什么想法了,问题是什么。下面的代码是Visual 2015新创建的WebApi项目。它没有任何变化。这根本行不通。
答复如下:
<Error>
<Message>
No HTTP resource was found that matches the request URI 'http://.../services/webapi2/api/dummies/dummymethod'.
</Message>
<MessageDetail>
No type was found
https://localhost:44301/weatherforecast I有一个asp.net web api (app1),它在我的机器中与本地主机一起运行。
其他asp.net web api (app2),它是我通过azure应用程序服务托管的,https://webapiapp120200626111110.azurewebsites.net/weatherforecast调用app1的api https://localhost:44301/weatherforecast。
使用var client =新的MediaTypeWithQualityHeaderValue("
我正在用ASP.NET Framework4.0和C#开发一个Web应用程序。
我有这个:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace MyProject.Web.Api.Controllers
{
public class UserADController : ApiController
{
[HttpGet]
为什么这个url()可以匹配路由寺庙(openapi/i{controller}.{action}/),而url()不匹配?
这是Microsoft.AspNet.WebApi 5.2.4我有谷歌并尝试所有条件,仍然没有结果,我需要一些帮助,他们!
1.WebApiConfig.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace TestRegion
{
public static class WebApiConfig
{
我是asp.net的新手。我想使用asp.net创建一个web服务。我使用完成了一个项目。
我有这样的课:
public class QRCodeItem
{
[Key]
public Byte Version { get; set; }
public int PrintPPI { get; set; }
public int CellSize { get; set; }
}
[Route("api/QRCode")]
[ApiController]
public class QRCodeController