asp.net-web-api

React component has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource

放肆的年华 提交于 2021-01-27 14:21:16
问题 I am calling the Web API from the my react component using fetch when I used to run it as one application, there was no problem, but when I am running the application react separate from API, I am getting the CORS error, my fetch call is as below, componentDidMount() { console.log(clientConfiguration) fetch(clientConfiguration['communitiesApi.local']) .then((response) => { return response.json(); }) .then(data => { console.log(data); let communitiesFromApi = data.map(community => { return {

React component has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource

梦想与她 提交于 2021-01-27 14:07:41
问题 I am calling the Web API from the my react component using fetch when I used to run it as one application, there was no problem, but when I am running the application react separate from API, I am getting the CORS error, my fetch call is as below, componentDidMount() { console.log(clientConfiguration) fetch(clientConfiguration['communitiesApi.local']) .then((response) => { return response.json(); }) .then(data => { console.log(data); let communitiesFromApi = data.map(community => { return {

Is it possible to get real-time data via a URL call to a Web API?

妖精的绣舞 提交于 2021-01-27 12:58:10
问题 Let's say you have an ASP.NET MVC 4 Web API project. One of your resources, when you call it by URL, waits while it gets performance monitoring data for a specified amount of time and then returns it all in JSON form once it has completed. However, between entering the URL and when the process has completed, is there a way to return data dynamically, ie. at each second when performance data is retrieved and display it in the browser. Here's the issue: Calling an API resource via URL is static

JToken.WriteToAsync does not write to JsonWriter

拟墨画扇 提交于 2021-01-27 12:54:23
问题 I'm trying to create a middleware that changes the request in a certain way. I am able to read it and change the content but I cannot figure out how to correctly setup the stream writers to create a new body. When I call normalized.WriteToAsync(jsonWriter) the MemoryStream remains empty and consequently I receive the A non-empty request body is required. exception. What am I missing here? This is what I have so far: public async Task Invoke(HttpContext context) { if (context.Request

Choosing not to await async function in action in ASP.NET Core WebAPI controller

☆樱花仙子☆ 提交于 2021-01-27 08:01:54
问题 The scenario is the following: Backend: Asp.NET Core WebAPI 2.2 Frontend: iOS and Android which consumes the API I have a function allowing the user to send messages to other users. The sending of a message is done in an asynchronous action: public async Task<IActionResult> CreateMessage This action does the following in order: Validation Awaits persistance of the message to DB Awaits the notification of relevant clients via SignalR Doesn't await the sending of push notification via Azure

Choosing not to await async function in action in ASP.NET Core WebAPI controller

假装没事ソ 提交于 2021-01-27 08:01:44
问题 The scenario is the following: Backend: Asp.NET Core WebAPI 2.2 Frontend: iOS and Android which consumes the API I have a function allowing the user to send messages to other users. The sending of a message is done in an asynchronous action: public async Task<IActionResult> CreateMessage This action does the following in order: Validation Awaits persistance of the message to DB Awaits the notification of relevant clients via SignalR Doesn't await the sending of push notification via Azure

Choosing not to await async function in action in ASP.NET Core WebAPI controller

徘徊边缘 提交于 2021-01-27 08:01:03
问题 The scenario is the following: Backend: Asp.NET Core WebAPI 2.2 Frontend: iOS and Android which consumes the API I have a function allowing the user to send messages to other users. The sending of a message is done in an asynchronous action: public async Task<IActionResult> CreateMessage This action does the following in order: Validation Awaits persistance of the message to DB Awaits the notification of relevant clients via SignalR Doesn't await the sending of push notification via Azure

Create mime/multipart request containing multiple HTTP requests

两盒软妹~` 提交于 2021-01-27 07:56:04
问题 I am following this tutorial for batching http requests with ASP.NET 4.5. I have the sample working, and now I need to write a client application in Python. This code creates, and sends a batch request to the web api: JsonMediaTypeFormatter formatter = new JsonMediaTypeFormatter(); //Create a request to query for customers HttpRequestMessage queryCustomersRequest = new HttpRequestMessage(HttpMethod.Get, serviceUrl + "/Customers"); //Create a message to add a customer HttpRequestMessage

Create mime/multipart request containing multiple HTTP requests

风流意气都作罢 提交于 2021-01-27 07:52:20
问题 I am following this tutorial for batching http requests with ASP.NET 4.5. I have the sample working, and now I need to write a client application in Python. This code creates, and sends a batch request to the web api: JsonMediaTypeFormatter formatter = new JsonMediaTypeFormatter(); //Create a request to query for customers HttpRequestMessage queryCustomersRequest = new HttpRequestMessage(HttpMethod.Get, serviceUrl + "/Customers"); //Create a message to add a customer HttpRequestMessage

Model validation in Web API - Exception is thrown with out a throw statement?

ぃ、小莉子 提交于 2021-01-27 07:41:00
问题 I have seen the model validation from here (Under section: Handling Validation Errors ). The code-snippet is as below in Web API public class ValidateModel : ActionFilterAttribute { public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext) { if (actionContext.ModelState.IsValid == false) { actionContext.Response = actionContext.Request.CreateErrorResponse( HttpStatusCode.BadRequest, actionContext.ModelState); } base.OnActionExecuting(actionContext); }