asp.net-core-webapi

File upload using Asp.Net Core Web API file is always null

怎甘沉沦 提交于 2019-12-07 03:25:16
问题 I am implememting file upload using Angular 2 with ASP.NET core Web API to handle the request. My html code looks like : <input #fileInput type="file"/> <button (click)="addFile()">Add</button> and the angular2 code addFile(): void { let fi = this.fileInput.nativeElement; if (fi.files && fi.files[0]) { let fileToUpload = fi.files[0]; this.documentService .uploadFile(fileToUpload) .subscribe(res => { console.log(res); }); } } and the service looks like public uploadFile(file: any): Observable

Can you set request timeout in asp.net core 2.0 hosted in IIS from C# code?

核能气质少年 提交于 2019-12-07 03:14:41
问题 Is there a way to set requestTimeout from C# instead of needing to set requestTimeout in the web.config ? asp.net core 2.0 hosted in IIS <?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <handlers> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" /> </handlers> <aspNetCore requestTimeout="00:00:04" processPath="dotnet" arguments=".\Foo.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" /> </system.webServer> <

Why am I getting the error “Cannot instantiate implementation type” for my generic service?

徘徊边缘 提交于 2019-12-06 23:47:46
问题 I have a generic repository that I have been instantiating right in my WEB API Controller no problem for a while. This is what my controller used to look like: [Route("api/[controller]")] public class EmployeesController : Controller { private IGenericRepository<Employee> _empRepo; public EmployeesController(IGenericRepository<Employee> employeeRepo) { _empRepo = employeeRepo; } // GET: api/employees [HttpGet] public async Task<IEnumerable<Employee>> GetEmployeesAsync( string firstName = null

Client certificate is always null

孤人 提交于 2019-12-06 15:51:35
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.EnsureSuccessStatusCode(); string responseContent = response.Content.ReadAsStringAsync().Result; Console.WriteLine

Limiting accessing Web API to application

人盡茶涼 提交于 2019-12-06 14:37:35
问题 We're building a cross-platform app using Ionic and using ASP.NET Core WebAPI hosted on azure. We are using Identity authentication system but we need to restrict access to this API to our application. So if other apps or sites try to access the API they will be blocked. Please note: The webapp is SSL secured I have been told that sending a shared code is not useful as it can be taken from the binary Kindly give me your suggestion to solve this problem. 回答1: As requested, here is a shell of a

Attaching httpHandler to httpclientFactory webapi aspnetcore 2.1

一笑奈何 提交于 2019-12-06 12:06: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 HttpClientHandler { AllowAutoRedirect = false, AutomaticDecompression = DecompressionMethods.Deflate |

Install nginx on an existing asp.net core docker container

纵然是瞬间 提交于 2019-12-06 11:18:03
I'm currently running a docker container for an ASP.NET Core WebAPI project. This web service is currently exposed on port 80. My dockerfile looks like this: FROM microsoft/dotnet:2.1-aspnetcore-runtime ARG source WORKDIR /app EXPOSE 80 COPY ${source:-obj/Docker/publish} . ENTRYPOINT ["dotnet", "testapi.dll"] I'd like to install nginx as a layer between the service and the exposed public network. The final result should be ASP.NET running on port 90 which is internal only and an nginx webserver forwarding the local 90 to public 80 port. Is this possible? if so, how can I achieve such

Manage versioned API in Azure API Manager

喜夏-厌秋 提交于 2019-12-06 11:02:20
I´m looking into host our web API in Azure using an API app. I am using the Azure API Manager in front of the API App to expose the developer portal to some of our consumers. The web API is built in .NET core and it has version support using the URL ( https://example.com/api/v2/controller.. .). I have given it swagger support and one swagger.json is created for each version. These swagger files I use in my ARM templates to set up API Manager and expose this versioned API. When adding a version to API Manager I have to give a path which must be unique for the API Im adding. So for version v1 I

How to set default datetime format for .net core 2.0 webapi

流过昼夜 提交于 2019-12-06 08:34:27
Currently in my local. The API is expecting the same formart as in SQL Server database which is yyyy-mm-dd. However when i am deploying the application into production server. The API is expecting the datetime format as yyyy-dd-mm. Is there any way to configure my .net core web api to accept yyyy-mm-dd as default format in every enviroment? 100% of the time, If I am using DateTime , I create an interface for it. It just makes life a lot easier when it's time for testing. I believe this would work for you as well. There's a couple of reasons for this method. It's testable. It abstracts the

adding to azure blob storage with stream

天大地大妈咪最大 提交于 2019-12-06 07:43:31
I am trying to add an IFormFile received via a .net core web API to an azure blob storage. These are the properties I have set up: static internal CloudStorageAccount StorageAccount => new CloudStorageAccount(new StorageCredentials(AccountName, AccessKey, AccessKeyName), true); // Create a blob client. static internal CloudBlobClient BlobClient => StorageAccount.CreateCloudBlobClient(); // Get a reference to a container static internal CloudBlobContainer Container(string ContainerName) => BlobClient.GetContainerReference(ContainerName); static internal CloudBlobContainer ProfilePicContainer =>