asp.net-core-webapi

I want to place Automapper profile in my Business Layer

孤街浪徒 提交于 2019-12-11 11:04:22
问题 I've created a web api core 2.0 application. I've got my main app and the Business Layer. I want to place the automapper profile in the business layer so that all the mappings are made in the business layer. My business layer is just a class library project. Is this possible? or do I need to place all my mapping in a Profile class in the main app? Just a theoretical explanation can help. 回答1: Yes, it's possible but it depends on where the model classes reside. You can give each layer or

.Net Core controller to update array, but only with included properties

隐身守侯 提交于 2019-12-11 08:52:17
问题 When I PUT to my controller for an update, I can use code like the following to ensure that only those properties that are specified in the object are updated. In other words, if I had a ControlLinePointDto object with properties ID, X, Y and Z, the following would only update property X JSON { "key" : 5, "values" : { "X": 1234 } } Controller [HttpPut] public async Task<IActionResult> PutControlLinePoint(int key, string values) { if (!ModelState.IsValid) return BadRequest(ModelState); int id

ASP.Net Core Web API Build Error - MSB4019 The imported project Microsoft.DotNet.Props was not found. Confirm that the path in the <Import>

久未见 提交于 2019-12-11 08:27:30
问题 I am getting the following error in my ASP.Net Core Web API Project , after I added Sqlite Reference (see below) and also changed the Microsoft.NETCore.App dependency version in project.json from 1.0.1 (which was working) to 1.1.0 (which is breaking the build with the following error). Error MSB4019 The imported project "C:\Program Files\dotnet\sdk\1.0.1\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Props" was not found. Confirm that the path in the declaration is correct, and that the

Enabling CORS in Web API Core and Angular JS

只愿长相守 提交于 2019-12-11 07:56:26
问题 I have an WEB API Core hosted in a different local host and I am trying to access it from my MVC Core app through AngularJS $http service. Here is my homeController.js app.controller("homeController", function ($scope, $http) { $scope.accessToken = ""; var serviceBase = "https://localhost:44351/"; var request = $http({ method: "post", url: serviceBase + "api/token", data: { username: "DemoUser", password: "Password" }, headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=utf

Azure AD connect multiple apps to single Web API

一个人想着一个人 提交于 2019-12-11 07:48:01
问题 I have a Web API written using asp.net core. This API will be used to communicate with several other services registered in AAD, which all could be made using different technologies like an MVC application written in asp.net core or a single page application written in Vue.JS. The latter is causing me issues as the SPA won't be run by an application web server and rather something like nginx or apache and therefor won't be able to use a client secret. I have added API permissions for my API

AllowAnyMethod works for some API calls but not for others

拟墨画扇 提交于 2019-12-11 07:45:08
问题 I have the form mentioned in this question, but when I submit it I get Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:1113/api/loans. (Reason: CORS header 'Access-Control-Allow-Origin' missing). and Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:1113/api/loans. (Reason: CORS request did not succeed). I had fixed this for another API call previously by adding this to

Creating single application with multi dbs

眉间皱痕 提交于 2019-12-11 06:38:21
问题 I don't think I described the problem properly through the title. However, I have a .NET Core Web Api application which all of my tenants will use. As well as the single API instance I have a single frontend Vuejs instance which all tenants can use as a 'portal'. These tenants each have their own database. Currently the api's all require a header of tenant within a request to specify which tenant the request is being made for, this will then create a db connection according to the tenant from

SwaggerUI with .NetCore 3.0 bearer token authorization

半城伤御伤魂 提交于 2019-12-11 04:47:36
问题 I'm trying to add authorization header into SwaggerUI api test. below is my Startup.cs public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.Configure<ApiBehaviorOptions>(options => { options.SuppressModelStateInvalidFilter = true; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "API", Description = "QPIN API with ASP.NET Core 3

Angular 2 Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header

时光总嘲笑我的痴心妄想 提交于 2019-12-11 04:47:17
问题 I'm new to Angular2. And I'm trying to call POST method to my .net core API.It's working fine with Postman.But when I call it from my angular 2 service it gives an error. This is my api.service.ts import { Injectable } from '@angular/core'; import { environment } from '../../../environments/environment'; import { Headers, Http, Response, URLSearchParams } from '@angular/http'; import { Observable } from 'rxjs/Rx'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; import {

HttpContext null in constructor

旧时模样 提交于 2019-12-11 04:40:16
问题 I have a UserContext Service where I'll put some basic functionalities (" IsAuthenticated , GetUser etc...) In order to do that, I need to pass the HTTPContext from my WebAPI Controller to my Class Library Service. Actually, HttpContext is always null in the web api controller. Anybody have a solution to resolve my issue ?. Is there a better way to acheive it. Web API User Controller [Route("api/[controller]")] [Authorize] public class UserController : Controller { private readonly