asp.net-core-webapi

Anti forgery with token API and angular

只谈情不闲聊 提交于 2020-02-16 08:23:09
问题 I am working on Angular 6 application with SSO login and .net core web API. The code hits the back end on /token url first time which is a post operation. How do I do the anti forgery in this scenario. Please explain the flow of token transfer 回答1: I'm not sure if that's what you're looking for, but I'll try to explain how I achieved it in a similar case. First of all Angular has built in helpers for XSRF handling: https://angular.io/guide/security#http https://angular.io/api/common/http

How to get value of specific key from resource file in ASPNET Core?

烈酒焚心 提交于 2020-02-06 07:48:13
问题 I wanna get value of a key in resource (.resx) file in .net core API. I followed the marked answer and implemented in my code. But When I am fetching value by key then only Key name is coming. The linked is below which I followed : How to get the .resx file strings in asp.net core Please help me for this. Thanks 回答1: Here is a working example , you could refer to : Startup.cs public void ConfigureServices(IServiceCollection services) { var connection = @"Server=(localdb)\mssqllocaldb;Database

How to get value of specific key from resource file in ASPNET Core?

旧城冷巷雨未停 提交于 2020-02-06 07:44:31
问题 I wanna get value of a key in resource (.resx) file in .net core API. I followed the marked answer and implemented in my code. But When I am fetching value by key then only Key name is coming. The linked is below which I followed : How to get the .resx file strings in asp.net core Please help me for this. Thanks 回答1: Here is a working example , you could refer to : Startup.cs public void ConfigureServices(IServiceCollection services) { var connection = @"Server=(localdb)\mssqllocaldb;Database

Send image from ionic to asp.net core web api

倖福魔咒の 提交于 2020-02-06 06:39:46
问题 We are looking to upload image from ionic to .net core web api. To achieve this we are using file transfer plugin. So, far we understood that image will be converted into base64. However, what we are looking is how can we sent form data along with multiple image to web api? Below is the code from ionic side. HTML code to trigger select image function: <ion-button fill="clear" expand="full" color="light" (click)="selectImage()"> <ion-icon slot="start" name="camera"></ion-icon> Select Image<

How to ConfigureServices in Asp.Net core WebAPI from another assembly

浪子不回头ぞ 提交于 2020-02-05 09:53:29
问题 In a microservice environment I need to construct a framework for Contract based testing. I'm currently investigatingh how to isolate a single service from it's external dependencies inorder to execute the Provider tests. What I need to do is: Keep the WebApi project intact Start an instance of the WepApi with some config-differences Mock out selected dependencies My Solution structure is this: Case-Solution/ ├── src/ | ├──Case.Api | └──Case.Application ├── test/ | ├──Case.Api.Unittest | ├──

Use Cors based on an appSettings in .Net Core

南笙酒味 提交于 2020-02-05 04:21:09
问题 I am updating a .net 4.5.2 project to .Net core web api. Right now, the Cors is setup as below based on an appSetting value CorsAllowAll : if ((ConfigurationManager.AppSettings["CorsAllowAll"] ?? "false") == "true") { appBuilder.UseCors(CorsOptions.AllowAll); } else { ConfigureCors(appBuilder); } private void ConfigureCors(IAppBuilder appBuilder) { appBuilder.UseCors(new CorsOptions { PolicyProvider = new CorsPolicyProvider { PolicyResolver = context => { var policy = new CorsPolicy(); policy

Attaching httpHandler to httpclientFactory webapi aspnetcore 2.1

拜拜、爱过 提交于 2020-02-02 12:14:46
问题 I am trying to attach an handler to httpclientfactory using "ConfigurePrimaryHttpMessageHandler" but when I look inside the HttpClient to see if the handler is there i cannot find it Am I attaching the handler correctly? Any Suggesions services.AddHttpClient<IGitHubClient,GitHubClient>(client => { client.BaseAddress = new Uri(myUri); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); }) .ConfigurePrimaryHttpMessageHandler(() => new

Attaching httpHandler to httpclientFactory webapi aspnetcore 2.1

僤鯓⒐⒋嵵緔 提交于 2020-02-02 12:14:08
问题 I am trying to attach an handler to httpclientfactory using "ConfigurePrimaryHttpMessageHandler" but when I look inside the HttpClient to see if the handler is there i cannot find it Am I attaching the handler correctly? Any Suggesions services.AddHttpClient<IGitHubClient,GitHubClient>(client => { client.BaseAddress = new Uri(myUri); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); }) .ConfigurePrimaryHttpMessageHandler(() => new

Implement Pagination in ASP.NET Core 2.1 Web API

佐手、 提交于 2020-02-02 02:48:09
问题 I searched, but did't really found articles on how to implement pagination logic in an ASP.NET WebAPI Core 2.1 application... I have the following [Route("api/[controller]")] [ApiController] [EnableCors("AllowMyOrigin")] public class EntriesController : ControllerBase { private readonly EntriesContext _context; public EntriesController(EntriesContext context) { _context = context; if (_context.Entries.Count() == 0) { _context.Entries.Add(new Entry { From = "default", To = "default" });

Returning a 404 from an explicitly typed ASP.NET Core API controller (not IActionResult)

♀尐吖头ヾ 提交于 2020-01-30 15:21:13
问题 ASP.NET Core API controllers typically return explicit types (and do so by default if you create a new project), something like: [Route("api/[controller]")] public class ThingsController : Controller { // GET api/things [HttpGet] public async Task<IEnumerable<Thing>> GetAsync() { //... } // GET api/things/5 [HttpGet("{id}")] public async Task<Thing> GetAsync(int id) { Thing thingFromDB = await GetThingFromDBAsync(); if(thingFromDB == null) return null; // This returns HTTP 204 // Process