asp.net-web-api2

Routing error: No HTTP resource was found that matches the request URI

柔情痞子 提交于 2019-12-13 03:24:33
问题 I'm trying to make the API call http://localhost:56578/v1/reports to call my GetReports() method. However I continue to get the error message in the subject. I'm following the ms docs here via the route prefix: https://docs.microsoft.com/en-us/aspnet/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2#route-prefixes What am I doing wrong? ReportV1Controller.cs [Authorize] [RoutePrefix("v1/reports")] .... .... [Route("")] public IHttpActionResult GetReports()

404 Error when accessing Web API 2 service

雨燕双飞 提交于 2019-12-13 02:36:35
问题 I have a WebAPI2 web service that works on my DEV site as well as on a local staging site, but when I push to production I get a 404 error when trying to access the same services. Here's an example of the problem ... // production server returns 404 Error http://my.servername.com/AppAPI/CustomerAPI/Session/4 // local stage site works http://localhost:100/AppAPI/CustomerAPI/Session/4 I know that there are a number of reasons why a 404 could result. Bad routes came to mind first and seem to be

adding cors to aspx web api 2 hybrid

一笑奈何 提交于 2019-12-13 02:35:47
问题 I've added Web API 2 to an existing vb aspx web forms project. and the routing went into the global asax application_start because I do not have an app_start folder with WebApiConfig as you do in a standard web api project. I downloaded CORS from the nugget package manager add attempted to enable CORS Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application is started RouteTable.Routes.MapHttpRoute( name:="DefaultApi", routeTemplate:="api/{controller}/

IAutofacActionFilter injecting a logger

杀马特。学长 韩版系。学妹 提交于 2019-12-13 02:04:41
问题 I'm using NLog with this module: public class LoggingModule : Autofac.Module { protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration) { registration.Preparing += OnComponentPreparing; registration.Activated += (sender, e) => InjectLoggerProperties(e.Instance); } private static void OnComponentPreparing(object sender, PreparingEventArgs e) { var t = e.Component.Activator.LimitType; e.Parameters = e.Parameters.Union( new[

Web API Routing - Only actions with a URI parameter work

旧城冷巷雨未停 提交于 2019-12-13 00:09:31
问题 I had a web API project that was working fine. I merged it with an MVC project, and now only the actions with a URI parameter work. All other actions end up with a 404 Not Found where even the controller is not found. Here's what I have in WebApiConfig (standard stuff): public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Web API configuration and services // Configure Web API to use only bearer token authentication. config

Serializing Dictionary<string,string> to array of “name”: “value”

三世轮回 提交于 2019-12-12 23:18:16
问题 I have this simple model in an ASP.NET WebAPI 2 application: public class Model { public int ID { get; set; } public Dictionary<string, string> Dic { get; set; } } When it gets serialized, the output is: { "ID": 0, "Dic": { "name1": "value1", "name2": "value2" } } I searched the problem, but it seems most people need this serialization: { "ID": 0, "Dic": [{ "Key": "name1", "Value": "value1" }] } And all solutions out there are resolving to that kind of serialization. But what I'm looking for

Ignore UTC offsets when deserializing with Json.NET

心不动则不痛 提交于 2019-12-12 20:50:28
问题 I've written a REST endpoint with ASP.NET Web API 2 that receives dates. The backend system has no concept of UTC times or DST, the dates stored in the database are just the UK date and time. The website feeding the endpoint, however, is including UTC offset values in the data sent to the end point (e.g. a date looks like "1939-01-08T00:00:00+01:00"). This happens when a summer date is entered in the winter or vice-versa (because of the adjustment for DST). Is it possible for me to set the

Modify the Http Status Code text

流过昼夜 提交于 2019-12-12 18:24:30
问题 Question How to modify the Status Code text (description/title)? Example For example: I want to change 200 (Ok) to 200 (My Custom Text) Desciption I want to create a HTTP response with custom Status Code (unreserved) 431. I want to modify it's text: 200 (OK) 400 (Bad Request) 431 (My message here) I've tried: var response = new HttpResponseMessage() { StatusCode = (HttpStatusCode) 431, }; response.Headers.Add("Status Code", "431 My custom text"); // This throws error. 回答1: Just add

HTTP 405 Errors after Publishing Web API 2 Applications

淺唱寂寞╮ 提交于 2019-12-12 18:13:07
问题 I have a Web Api Controller and i have tested all actions on localhost and it works well.But when i Published it on Web Server,Just Actions with [HttpGet] works and [HttpPost] Actions return Http 405 error public class ContentController : ApiController { [HttpGet] public async Task<IHttpActionResult> AdvantageList() { //return ok 200 } [HttpPost] public async Task<IHttpActionResult> SaveAdvantage(ContentModel model) { //return 405 } } I used below method on client var r = await ClientManager

Web Api 2 receive json array

∥☆過路亽.° 提交于 2019-12-12 17:34:22
问题 model public class modelVenta { public int idvendedor { get; set; } public int idcliente { get; set; } public int idproducto { get; set; } public int cantidad { get; set; } public decimal precio { get; set; } public DateTime fecha { get; set; } } public class modelVentas { public List<string> modeloVenta { get; set; } } Controller [HttpPut] [Route("api/ventas/Add")] public HttpResponseMessage putVentas( List<modelVentas> data) { return new HttpResponseMessage { StatusCode = HttpStatusCode.OK