asp.net-web-api

Issue in Enabling CORS for Web API 1, .net 4.0

随声附和 提交于 2020-06-22 13:04:53
问题 I need to enable CORS for my Web API and I can't upgrade to Framework 4.5. I've tried to add the following to my Web.config to see if it worked, but it didn't: <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Headers" value="Accept,Content-Type,X-Requested-With"/> I am accessing the URL http://localhost:8484/api/values/ from ajax call and getting bellow error XMLHttpRequest cannot load http://localhost:8484/api/values. Response to preflight request doesn't

Issue in Enabling CORS for Web API 1, .net 4.0

允我心安 提交于 2020-06-22 13:03:26
问题 I need to enable CORS for my Web API and I can't upgrade to Framework 4.5. I've tried to add the following to my Web.config to see if it worked, but it didn't: <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Headers" value="Accept,Content-Type,X-Requested-With"/> I am accessing the URL http://localhost:8484/api/values/ from ajax call and getting bellow error XMLHttpRequest cannot load http://localhost:8484/api/values. Response to preflight request doesn't

Use latest version of Application Insight with .net core API

此生再无相见时 提交于 2020-06-17 14:42:30
问题 I have an existing API project in .net core 3.0 and also using exception middleware to log the exception. Now there is an requirement that we need to implement application insight in our API. I go through many links, but getting that some methods are already obsolete for newer version like app.UseApplicationInsightsExceptionTelemetry() and UseApplicationInsightsRequestTelemetry . Even I tried to use TelemetryClient inside the catch block of middleware, but again it is obsolete already. So

using the $filter inside the $expand in the Odata query

梦想的初衷 提交于 2020-06-16 07:22:05
问题 I am trying to use the filter in the expanded entity using the Odata query like https://labstest.science.com/DEV/odata/ROOM_REQUEST?$expand=REQ_COLONYROOM($select=Name;$filter=Name eq 'RB05') This works partially. It brings all the ROOM_REQUEST with Null for the REQ_COLONYROOM where Name is not equal to RB05 { "@odata.context": "https://labstest.science.com/DEV/odata/$metadata#ROOM_REQUEST(REQ_COLONYROOM(Name))", "value": [ { "Id": 18399308, "Name": "M1", "Barcode": "M1", "REQ_COLONYROOM":

Calling WEB API with basic authentication in C#

只愿长相守 提交于 2020-06-12 16:43:38
问题 I have a working WEB API that I wrote, and I added basic authentication to the API (username is "testing", password is "123456"). However, when trying to call that API from my web form, I keep getting the "(401) Unauthorized" message. What should I change in the web code to call the API successfully? string url = String.Format("http://example.com"); //here I have the correct url for my API HttpWebRequest requestObj = (HttpWebRequest)WebRequest.Create(url); requestObj.Method = "Get";

Calling WEB API with basic authentication in C#

三世轮回 提交于 2020-06-12 16:43:31
问题 I have a working WEB API that I wrote, and I added basic authentication to the API (username is "testing", password is "123456"). However, when trying to call that API from my web form, I keep getting the "(401) Unauthorized" message. What should I change in the web code to call the API successfully? string url = String.Format("http://example.com"); //here I have the correct url for my API HttpWebRequest requestObj = (HttpWebRequest)WebRequest.Create(url); requestObj.Method = "Get";

Calling WEB API with basic authentication in C#

我与影子孤独终老i 提交于 2020-06-12 16:43:09
问题 I have a working WEB API that I wrote, and I added basic authentication to the API (username is "testing", password is "123456"). However, when trying to call that API from my web form, I keep getting the "(401) Unauthorized" message. What should I change in the web code to call the API successfully? string url = String.Format("http://example.com"); //here I have the correct url for my API HttpWebRequest requestObj = (HttpWebRequest)WebRequest.Create(url); requestObj.Method = "Get";

MVC5 Web API and Dependency Injection

天涯浪子 提交于 2020-06-12 07:15:11
问题 Trying to do some DI on Web API 2 without third-party tools. So, from some examples I've got custom dependency resolver (why there's no integrated one? Strange, even Microsoft.Extensions.DependencyInjection provides nothing): public class DependencyResolver : IDependencyResolver { protected IServiceProvider _serviceProvider; public DependencyResolver(IServiceProvider serviceProvider) { this._serviceProvider = serviceProvider; } public IDependencyScope BeginScope() { return this; } public void

MVC5 Web API and Dependency Injection

倾然丶 夕夏残阳落幕 提交于 2020-06-12 07:14:48
问题 Trying to do some DI on Web API 2 without third-party tools. So, from some examples I've got custom dependency resolver (why there's no integrated one? Strange, even Microsoft.Extensions.DependencyInjection provides nothing): public class DependencyResolver : IDependencyResolver { protected IServiceProvider _serviceProvider; public DependencyResolver(IServiceProvider serviceProvider) { this._serviceProvider = serviceProvider; } public IDependencyScope BeginScope() { return this; } public void

How can I host ASP.NET API and Blazor Web Assembly like an JavaScript-SPA?

余生长醉 提交于 2020-06-11 07:55:08
问题 Context: We want to create a Single Page Application that runs with Blazor WebAssembly on the client-side. On the server-side, the solution has an ASP.NET MVC which includes some ApiController classes for our REST APIs. We want to use ASP.NET API on the server-side instead of Blazor Server because we want to provide a REST interface with ApiController classes for unknown consumers. Here is my client-side (Blazor WebAssembly) and server-side (ASP.NET API) project in a single solution: A first