asp.net-core-webapi

EF Core 3.1 throws an exception for Contains

柔情痞子 提交于 2020-07-09 12:05:22
问题 I recently updated the project code into .NET Core 3.1 and EF Core 3.1, now most of my linq queries brake, EX. public override ICollection<ContactDetailModel> GetAll(ICollection<int> ids) { return _context .Set<TEntity>() .IgnoreDeletedEntities() .Where(x => ids.Distinct().Contains(x.ContactId)) .Select(EntityToDTOMapper) .ToList(); } This code throws an error where I use Contains, I saw in some other posts this issues has been fixed as a bug, but yet it fails. Error I get is "could not be

EF Core 3.1 throws an exception for Contains

怎甘沉沦 提交于 2020-07-09 12:05:08
问题 I recently updated the project code into .NET Core 3.1 and EF Core 3.1, now most of my linq queries brake, EX. public override ICollection<ContactDetailModel> GetAll(ICollection<int> ids) { return _context .Set<TEntity>() .IgnoreDeletedEntities() .Where(x => ids.Distinct().Contains(x.ContactId)) .Select(EntityToDTOMapper) .ToList(); } This code throws an error where I use Contains, I saw in some other posts this issues has been fixed as a bug, but yet it fails. Error I get is "could not be

Download large file from URL in .net core web api

久未见 提交于 2020-06-29 04:06:55
问题 In .net framework 4.7, I was able to use this logic to stream file from another URL (in Chunks), but in .net core System.Web.HttpContext and HttpResponse are not available. Any help pls, to achieve this objective of downloading in chunks from another URL, in .net core 3.1. The HttpContext.Current.Response , IsClientConnected etc are not available in .net core, //Create a stream for the file Stream stream = null; //chunk of bytes to read at a time and send to the client int bytesToRead = 10000

Unable to access the webapi from angular 8 application

我们两清 提交于 2020-06-29 03:43:07
问题 I have implemented an asp.net core web api and the endpoints seems to work fine. I am running the webapi via its local webserver. I am able to access the api via postman as well. I have implemented an Angular 8 application. I am getting an unknown error while trying to access the api endpoint. I initially thought it is cors issue and enabled cors in my controller but still facing the same problem. Could somebody tell me what the problem could be The webapi ur is http://localhost:56676/api

How to configure Anti-Forgery Protection in a view-less Web API

倾然丶 夕夏残阳落幕 提交于 2020-06-27 16:29:26
问题 I'm implementing a REST API using ASP.NET Core. It is stateless except for the fact that is uses cookies for authentication and therefore is vulnerable to cross-site request forgery (CSRF) attacks. Luckily, ASP.NET Core provides means as a protection against that: Prevent Cross-Site Request Forgery (XSRF/CSRF) attacks in ASP.NET Core. As my application does not have any views or pages, I'm only configuring my controllers using services.AddControllers() in my Startup . When hitting a REST

Invoking SignalR Hub not working for Asp.Net Core Web API

泪湿孤枕 提交于 2020-06-27 09:10:29
问题 I'm a newb to SignalR. I'm trying to set up a Asp.Net Core WebAPI so that other clients can connect to it using SignalR and get real-time data. My Hub class is: public class TimeHub : Hub { public async Task UpdateTime(string message) { await Clients.All.SendAsync("ReceiveMessage", message); } } I have a relay class as follows: public class TimeRelay : ITimeRelay { private readonly IHubContext<TimeHub> _timeHubContext; public TimeRelay(IHubContext<TimeHub> context) { _timeHubContext = context

405 (Method Not Allowed) and blocked by CORS policy

梦想的初衷 提交于 2020-06-26 12:23:05
问题 I have Asp.Net Core(3) WebApi project with UI based on Angular(7.2.1) on Client side. When using Postman or just using the URL I can use GET and POST without any particular errors. When trying the same by Angular(Chrome\FireFox\IE Browser) I'm getting the following errors. zone.js:3243 OPTIONS http://localhost:8888/api/PaymentDetails 405 (Method Not Allowed) ccess to XMLHttpRequest at 'http://localhost:8888/api/PaymentDetails' from origin 'http://localhost:4200' has been blocked by CORS

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

ASP.NET Core: Is it possible to use HttpClient to fetch a file and return directly?

烈酒焚心 提交于 2020-06-17 13:20:08
问题 I have an internal API that would fetch and return a fileresult. However, this API does not have any concept of authentication/role/permission checks and cannot be modified to do so. I would like to create an web API endpoint on an existing ASP.NET Core 2 Web API to do permission check, make a call to this internal API and return the fileresult back to a web client. Would it be possible to get the wrapper API endpoint to just pass whatever it fetches as a file result without having to

ready to use uint route constraint?

a 夏天 提交于 2020-06-16 18:37:14
问题 I have a .NET Core Web API project and my Ids are integers starting at 1. In most samples I see something like this [HttpGet("{id:int}")] public async Task<ActionResult<User>> GetUserByIdAsync([FromRoute] int id) { // ... } Since I know Ids must be greater than 0 I also added the :min(1) route constraint. But wouldn't it be better to change the integer datatype to uint ? The route would then be "{id:uint:min(1)}" and the method parameter will change to [FromRoute] uint id but unfortunately