asp.net web api 2

以下是为您整理出来关于【asp.net web api 2】合集内容,如果觉得还不错,请帮忙转发推荐。

【asp.net web api 2】技术教程文章

c# – 找不到ASP.NET Web API路由控制器【代码】

我想发布到以下Web API:http://localhost:8543/api/login/authenticateLoginApi(Web API)定义如下:[RoutePrefix("login")] public class LoginApi : ApiController {[HttpPost][Route("authenticate")]public string Authenticate(LoginViewModel loginViewModel){ return "Hello World"; } }WebApiConfig.cs:public static void Register(HttpConfiguration config) {// Web API configuration and services// Web API routes...

c# – 如何在ASP.NET web api中接收json?【代码】

我有一个外部公司将数据推送到我们的服务器之一,他们将发送JSON数据.我需要创建一个POST api来接收它.这就是我到目前为止所拥有的[System.Web.Http.HttpPost] [System.Web.Http.ActionName("sensor")] public void PushSensorData(String json) {string lines = null;try{System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt");file.WriteLine(json);file.Close();//JSONUtilities.deserialize(json);}catch ...

c# – 在ASP.NET Web API中从URI模型绑定到Dictionary【代码】

请参阅MVC:http://aspnetwebstack.codeplex.com/discussions/351011中的此链接 我遇到模型绑定问题.从JavaScript我执行GET Ajax请求到我的API端点“/ api / products”,传递一些参数,包括分页和排序作为查询参数.这是完整的URI:http://localhost/api/products?page=1&count=10&filter[name]=Test1&filter[price]=10&sorting[name]=desc在服务器端,我有一个Web API控制器从URI接受这些属性:public async IHttpActionResult Get([...

ASP.NET Web API:如何创建跨请求的持久性集合?【代码】

我有一个Web API,提供Angular.JS Web应用程序的后端.后端API需要跟踪用户活动的状态. (示例:它需要记录用户最后一次从API检索到的内容ID) 对API的大多数访问都通过用户名/密码进行身份验证.对于这些实例,将用户状态存储在我们的数据库中对我来说很好. 但是,我们确实需要允许“访客”访问服务.对于来宾,确实需要跟踪状态,但不应长期保留(例如,会话级跟踪).我真的不需要在用户表中生成“伪用户”来存储来宾用户的状态,而无需长时间维...

尝试从ASP.NET Web Api控制器返回IEnumerable【代码】

我试图从我的ASP.NET Web Api控制器返回一个IEnumerable ..我的ApiController中有以下内容…public IEnumerable<dynamic> Get(){var personRepository = new PersonRepository();var parameters = HttpUtility.ParseQueryString(Request.RequestUri.Query);return personRepository.GetAll(parameters).Select(x => new{Name = x.Name});}执行代码时,出现以下错误…<Error> <Message>An error has occurred.</Message> <ExceptionM...

c#-在asp.net Web API中上传文件之前检查文件扩展名【代码】

这是我的任务: >我需要使用Asp.Net Web API将图片上传到服务器.>在上传文件之前,我需要检查文件的扩展名(我只允许上传图片).>我需要将文件保存为Stream或Base64String,因为要在保存到服务器之前对其进行调整. 这是我尝试过的.我可以使用MultipartFormDataStreamProvider将文件上传到服务器,并且从该MultipartFormDataStreamProvider中插入CustomMultipartFormDataStreamProvider之后,就可以在GetStream方法中检查文件扩展名,例如:...

CodeGo.net>如何使用ASP.NET Web API与ASP.NET身份跨源?【代码】

我尝试了许多方法,但是没有在asp.net Web API中使用跨域.I’m trying to call from my domain mydomain.com to search.mydomain.com butit is not allowing as cross-origin is not allowed.如何在我的网站中启用跨域?任何帮助将不胜感激.解决方法:这是一篇关于跨域实现的很好的文章: https://askgif.com/blog/298/how-to-use-asp-net-web-api-cross-origin-with-asp-net-identity/ ASP.NET Web API是.NET系列的绝妙组成部分(肯定...

c#-Visual Studio中带有ASP.NET Web API项目的Angular项目【代码】

我在Visual Studio 2017中有两个项目的解决方案. 其中一个包含客户端SPA的所有Angular文件.另一个是ASP.NET Web API项目,该项目用作Angular前端进行的HTTP调用的端点. 我正在使用Angular CLI和ng-serve将我的角度应用程序部署到localhost:4200 Web API已部署到localhost:6463 在生产环境中,它们将属于同一域.但是,在开发中,它们不在同一域中,因为本地主机的端口不同.由于Angular应用程序不得不与Web api通信,因此迫使我实现CORS....

禁止在ASP.NET Web API中对JsonMediaTypeFormatter进行RequiredAttribute验证【代码】

假设我向API发送了以下请求:POST http://localhost:4940/api/cars HTTP/1.1 User-Agent: Fiddler Host: localhost:4940 Content-Type: application/json Content-Length: 44{"Make":"Make1","Year":2010,"Price":10732.2}而且我有以下Car类定义:public class Car {public int Id { get; set; }[Required][StringLength(20)]public string Make { get; set; }[Required][StringLength(20)]public string Model { get; set; }publi...

c#-纯asp.net Web API应用程序

我基于Web API模板创建了一个新项目,但发现它包含许多我不需要的不必要文件,例如常规的mvc路由,css,js,cshtml文件.我需要一个纯asp.net Web API应用程序,我可以从该项目模板中删除什么?解决方法:这很烦人-默认情况下,WebAPI没有“空”模板,因此您必须删除以下内容: > /区域/> /内容/> /图片/> /脚本/> /视图/> favicon.ico 这将使您拥有默认生成的Controllers和App_Start文件夹,以及Global.asax& Web.Config是纯WebAPI项目真正需...