asp.net-web-api2

Web API 2 Attribute Routing Controller Selection

给你一囗甜甜゛ 提交于 2019-12-13 06:27:01
问题 I use Web API 2 Attribute Routing in my project to provide JSON interface over my data. I am facing weird behaviour of controller selection, not decided yet whether it's a bug or a feature :) Let me describe my approach. I would like to simulate OData syntax with help of attribute routing (direct OData usage has been refused due to design principles). For example, to get entity with id=5 I use HTTP GET request to URI http://mydomain.com/api/Entity(5) . I expect to use the same URI with HTTP

How to use Roles with Integrated Windows Authentication

北城以北 提交于 2019-12-13 05:54:58
问题 I'm working on a Web Application implemented in ASP.NET MVC 5 with Web API 2. I've implemented Integrated Windows Authentication by adding the following code to web.config: <system.web> <authentication mode="Windows" /> </system.web> <system.webServer> <security> <authentication> <windowsAuthentication enabled="true"/> </authentication> </security> </system.webServer> and by adding [Authorize] annotation on top of my controllers. Now, I'm asked to give access to some functionality based on

Dynamics CRM Web Api Function: Illegal characters in path when using encodeURIComponent

◇◆丶佛笑我妖孽 提交于 2019-12-13 05:48:14
问题 I'm trying to use the Search Function (https://msdn.microsoft.com/en-us/library/mt608029.aspx) via the Dynamics CRM 2016 Web API. This is my code: var start = new Date(2016, 2, 1, 17, 0, 0); var end = new Date(2016, 2, 10, 18, 0, 0); var request = new Object(); request.AppointmentRequest = new Object(); request.AppointmentRequest.SearchWindowStart = start.toISOString(); request.AppointmentRequest.SearchWindowEnd = end.toISOString(); request.AppointmentRequest.ServiceId = "5f3b6e7f-48c0-e511

IIS serves a compressed (gzip) response to Chrome Postman but not to .NET HttpClient

岁酱吖の 提交于 2019-12-13 05:25:35
问题 I have created a REST web service using Web API 2.2 on a Windows Server 2008 R2 box running IIS 7.5. The problem that I'm having is that the web service is returning a compressed response (Content-Encoding: gzip) when I make the request through the Google Chrome Postman application. But when I make the same request using the .NET 4.5.1 HttpClient, the server does not return a compressed response (the Content-Encoding header is blank). Here is my C# code: var handler = new HttpClientHandler();

odata v4 Product({key})/GenerateVariants route misconfiguration

℡╲_俬逩灬. 提交于 2019-12-13 04:44:14
问题 There is a function on product that generates the variants as a list. Currently it returns: The related entity set could not be found from the OData path This is my WebApiConfig: builder.EntityType<Product>().Function("GenerateVariants").Returns<List<ProductVariant>>(); ////.Parameter<string>("save").OptionalParameter = true; This is my method on the ProductController //http://localhost:26696/odata/Products(b2a35842-7b68-e511-beda-6c71d92133bc)/GenerateVariants [HttpGet] [ODataRoute("Products

Self hosting Web API with OWIN on EC2

心不动则不痛 提交于 2019-12-13 04:42:05
问题 I followed step-by-step instructions from http://www.asp.net/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api. Here is the code of console application: namespace OWINTest { class Program { static void Main(string[] args) { string baseAddress = "http://localhost:1961/"; // Start OWIN host WebApp.Start<Startup>(url: baseAddress); ... } } class Startup { // This code configures Web API. The Startup class is specified as a type // parameter in the WebApp.Start method. public

How to select property from expanded property? ReceivedCalls/Caller?$select=Email' is not valid in a $select or $expand expression

好久不见. 提交于 2019-12-13 04:32:15
问题 I have a class: Person which has property public virtual ICollection<Call> ReceivedCalls { get; set; } Then the Call is : public class Call { public int Id { get; set; } public virtual Person Callee { get; set; } public virtual ApplicationUser Caller { get; set; } public DateTime TimeStamp { get; set; } } I have a PersonController and CallsController (both are scaffolded WEB API OData controllers). I can fetch people and their calls (and who called) by the link: http://localhost:17697/odata

Accessing route and POST params in Web Api 2 Controller Method

做~自己de王妃 提交于 2019-12-13 04:16:17
问题 I have a controller that needs access both route and POST body parameters. However when I use this implementation public class MessageController : ApiController { [Route( "Data/Message/{apiKey}/{userId}" )] [HttpPost] public Message Post( Guid apiKey, string userId, [FromBody] string message) { // ... } } the message argument is always null . How can I access all the apropos data? 回答1: [FromBody] parameters must be encoded as value don't you try to do this: public Message Post( Guid apiKey,

C# Web API 2 & Angular - Microsoft Account Authentication

早过忘川 提交于 2019-12-13 03:44:20
问题 I've asked the question below a couple weeks ago and I didn't get a working answer. Or maybe just not suitable for my case. C# Microsoft Authentication Get logged user from controller So I thought maybe I wasn't asking the right question. What i'm trying to do is create an app which has a C# Web API 2 backend and an Angular 2 frontend. Now, I want that my authentication be using people's Microsoft Account which means this will be an external authentication. What's the best way of doing this?

Web API not returning any data result

半腔热情 提交于 2019-12-13 03:43:43
问题 I have created a WEB API in visual studio 2015 using MySQL DB. Now when I run the API. I am getting {"Message":"No Data found"} exception. Below is my code Controller public class MetersInfoController : ApiController { public MeterEntities mEntities = new MeterEntities(); public HttpResponseMessage Get() { try { return Request.CreateResponse(HttpStatusCode.Found, mEntities.meters_info_dev.ToList()); } catch (Exception) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, "No Data