asp.net-core-webapi

ASP.NET Core 2.0 Web API Response Caching

旧城冷巷雨未停 提交于 2019-12-12 10:38:39
问题 I am trying to implement response caching in my web api using the "Microsoft.AspNetCore.ResponseCaching" package. I am using Postman to test the application and validate headers etc. The correct headers are generated with the specified max-age but postman seems to request the response from the api and not using the cache. The response time does not vary at all and if I debug the controller I can see that it gets hit by the request every time. Startup class ConfigureServices (along with other

App running in Android Emulator fails to perform an HTTP Post to localhost

拥有回忆 提交于 2019-12-12 06:56:32
问题 I'm unable to perform an HTTP Post with an app running in an Android Emulator . {StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.HttpConnection+HttpConnectionResponseContent, Headers: { Server: Microsoft-HTTPAPI/2.0 Date: Wed, 23 Oct 2019 00:58:01 GMT Connection: close Forwarded: host=XXX.XXX.X.XX:XXXXX; proto=https Content-Type: text/html; charset=us-ascii Content-Length: 374 }} Setup: I'm using an IP address generated by Conveyor by Keyoti I installed a

How to create a CDN server in dotnet core using MongoDB GridFS and AngularJs

坚强是说给别人听的谎言 提交于 2019-12-12 04:58:53
问题 We want to create a decoupled file server named CDN in .net core using MongoDB GridFS and angular js. From various sources I tried my best to solve the issue. And finally we done this. 回答1: I used Visual Studio 2017 and .NETCore 1.1 To do so I follow the followings: 1. Write Code in MongoDB GridFS create an interface like public interface IGridFsRepository : IDisposable { Task<string> UploadAsync(IFormFile file); Task<bool> AnyAsync(ObjectId id); Task<bool> AnyAsync(string fileName); Task

How to protect Web API called by IdentityServer4

陌路散爱 提交于 2019-12-12 04:38:21
问题 I make multiple calls to a Web API during login operations in IdentityServer4. Same applies during password reset operations which is custom code I have added to the IdentityServer4 project. So how should I protect my ASP.NET Core Web API when the user isn't yet authenticated via OIDC which implies that there also isn't exist any access token at that stage. I would like to only allow IdentityServer4 to call these Web API methods instead of running unprotected Web API's. Any suggestions? 回答1:

Doubting using Identity for ASP.NET Core Web API

佐手、 提交于 2019-12-12 03:05:39
问题 I'm working on a Web API and I am not sure if I did a mistake by avoiding using the Identity membership system and implementing my own authentication setup. From what I've read it looks like it's a great solution for frontend-ish logins such as Facebook where you can use UserManager to easily commit different CRUD's on users, etc but I've also seen it being used by other people for their Web API's. I didn't avoid it exclusively because of the upper paragraph but for the following excerpt from

How to get token details like access token,access token expiry time and refresh token etc. on OnAuthorization() method

点点圈 提交于 2019-12-11 20:09:27
问题 I want to eject a logic that if access token is expired then generate refresh token on onAuthorization(AuthorizationFilterContext context) method in ASP.NET WEB API Core . But i am not able to find a way to get token details.Basically how to get token details like expiry , refresh token from AuthorizationFilterContext . public void OnAuthorization(AuthorizationFilterContext context) { var user = context.HttpContext.User; if (!user.Identity.IsAuthenticated) { var test = context.; ..code to get

Get Azure AD Groups Before Building Authorization Policies

为君一笑 提交于 2019-12-11 19:45:07
问题 We're developing an application that uses a back-end built on .Net Core 2.2 Web API. Most of our controllers merely require the [Authorize] attribute with no policy specified. However, some endpoints are going to require the user to be in a particular Azure AD Security Group. For those cases, I implemented policies like this in the Startup.cs file: var name = "PolicyNameIndicatingGroup"; var id = Guid.NewGuid; // Actually, this is set to the object ID of the group in AD. services

Building filters on DbContext

青春壹個敷衍的年華 提交于 2019-12-11 19:17:29
问题 I have an ASP .Net Core 2.1 Web Api. I was wondering if there is an "elegant solution" for constructing filters on my DbContext based on query strings? So... say I have one [optional] query string: // GET: api/Accounts [HttpGet] public IEnumerable<File> GetAccount([FromQuery] bool? isActive) { if (isActive.HasValue) return _context.Accounts.Where(a => a.IsActive == isActive.Value); else return _context.Accounts; } Simple enough... But say I have a number of (optional) query strings: // GET:

Approach for archive big files in azure storage

可紊 提交于 2019-12-11 18:28:33
问题 I'm interested in what is approach for storing of sensitive data in cloud in your projects. I want to prepare proof of concept of feature which have to archive files in Azure. We are talking about samething around 30GB of new files per day. 10-2000 MB per file. My first idea was to use Azure Storage to store those files. Files should be send to storage via Azure App Service so I have to prepare some WEBApi. Based on this idea I am curious if there wont be any problems with sending such a big

HttpClient fails to post to web API

自作多情 提交于 2019-12-11 18:18:20
问题 I have a simple Angular form which I want to post a Loan object to a .net core web API. After submitting the form I can see this data in the console: Object { Id: 0, BorrowerName: "asd", RepaymentAmount: 11.5, FundingAmount: 10 } But my API action never gets called. What am I doing wrong? Api Action [HttpGet] public ActionResult<IEnumerable<Loan>> Get() { return _context.Loans; } Loan.cs public class Loan { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set;