asp.net-core-webapi

Implement log4net in asp.net core webapi

和自甴很熟 提交于 2019-12-08 14:08:49
问题 I have a asp.net core web api. As of now I'm using ILogger to log the messages. But ILogger doesn't have Fatal loglevel in it. There is Critical level, but our team requires Fatal word instead of Critical word.Is there any way I can tweak the work which gets printed to logs? If not, I want to replace ILogger with log4Net which has Fatal level in it.So this is what I have done , but somehow it is not working. I have multi layer architecture : WebApplication1 , WebApplication1.Helper . All

CORS issue when angular and web API(.NET core) is used [SOLVED] [duplicate]

左心房为你撑大大i 提交于 2019-12-08 14:08:35
问题 This question already has answers here : How to enable CORS in ASP.NET Core (7 answers) Closed 5 months ago . I have two separate project, one is WebAPI developed in .net Core 2.2 with Windows Authentication and other is Angular. I am stuck in CORS issue. I was able to handle GET request by using withCredentials: true in GET method option as mentioned below, where httpClient is from import { HttpClient } from '@angular/common/http': return this.httpClient.get(this.getWebApiServiceUrl('

Entity Framework Multiple Connections Error

我怕爱的太早我们不能终老 提交于 2019-12-08 12:54:57
问题 I have a scenario wherein I have multiple connection strings defined under appsettings.json like this: "ConnectionString": { "ConnectionZone1": "Server=(localdb)\\mssqllocaldb;Database=Blogging;Trusted_Connection=True;", "ConnectionZone2": "Server=localhost;Database=Blogging;Trusted_Connection=True;" }, This I have registered in my startup.cs file as well: public void ConfigureServices(IServiceCollection services) { services.AddDbContext<DbContextZone1>(options => options.UseSqlServer

Interception on .NET Core 2.0 Web API Controller By Using Autofac

泄露秘密 提交于 2019-12-08 07:29:27
问题 I am trying to use interceptions on .Net Core 2.0 WebApi Application by using Autofac but I couldnt succeed it on Controllers. What I try is First I created a basic webapi which has one default controller(ValuesController). Then I set up the autofac configuration as below. Project is working without any error, but interception doesnt seems to be running. What I am doing wrong ? Startup.cs public void ConfigureContainer(ContainerBuilder builder) { builder.Register(c => new CallLogger());

ASP.NET core background service to send data through signalR

核能气质少年 提交于 2019-12-08 05:46:10
问题 I'm using signalR to send data to clients from server. What I want to is check data in the table(MSSQL DB) and send the related data to clients through signalR. So I want to create some background service to check database and send data. I planned to use System.Threading.Thread.Sleep(3000); with while(true) loop. How can I create service class to run this method in startup. Is there any method to use do this task in standard way?? 回答1: You can use an IHostedService and IHubContext to

Client certificate is always null

大憨熊 提交于 2019-12-08 05:09:58
问题 I have a certificate installed under Personal as well as Trusted Root Certification Authorities Have tried using this bit of code to post to an endpoint: public void Post() { try { var clientCert = LoadFromStore("MyThumbprint"); var requestHandler = new WebRequestHandler(); requestHandler.ClientCertificates.Add(clientCert); var client = new HttpClient(requestHandler) { BaseAddress = new Uri("https://localhost:44430/") }; var response = client.GetAsync("api/test").Result; response

Why is IFormFile collection empty when sent from Dropzone.js?

痞子三分冷 提交于 2019-12-08 04:46:30
问题 I am trying to use Dropzone.js to send a collection of IFormFile (images) to the following ASP.NET Core 2.1 Api controller action: [HttpPost("[action]")] public async Task<IActionResult> Upload([FromForm] ICollection<IFormFile> files) { ... } I am able to successfully send files to this Api from Postman. But I cannot get it to send the files from my UI, which implements Dropzone. I am using an ASP form in a Razor page <div> <form action="/api/images/upload" class="dropzone needsclick dz

One JWT token for many services

半世苍凉 提交于 2019-12-07 22:16:22
问题 I am facing the problem with JWT Authentication in ASP.Net Core. The scenario looks following: I have a ASP.NET Core Web API, let's call it 'API A'. It is resonsible for generating JWT Token to user who provide correct login/password, then token is generating. I have second ASP.NET Core Web Api, called 'API B' which returns some data from database. I would like to be able to use JWT token, generated by 'API A' to authorize access to data from 'API B'. Is it possible to achieve it by using

.NET Core AWS RDS CONNECTION

本秂侑毒 提交于 2019-12-07 21:17:22
问题 I am creating a .NET Core Web API on Amazons AWS, Elastic Beanstalk. I am trying to add a database, but their guide to add a database does not work for .Net Core http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_NET.rds.html It says to get the relevant information using "ConfigurationManager.AppSettings;", but this is not possible in .NET Core. Can anybody give some inforamtion about how to get the database informations? ( "RDS_DB_NAME" "RDS_USERNAME" "RDS_PASSWORD" "RDS

When using an API route, return Http Response 401 instead of redirect to login page when not authorised

怎甘沉沦 提交于 2019-12-07 16:00:21
问题 I'm building an ASP.NET Core 2.0 website using MVC and WebAPI to provide access to a series of microservices. Where a WebAPI controller requires a user to be authenticated and authorised (using the Authorize attribute), any unauthorised or not-logged in user gets the response back as the entire HTML for the MVC login page. When unauthorised users access the API, I would like to return the HTTP status code 401 and its associated error message in the response, instead of an entire HTML page. I