Questions tagged [asp.net-core-2.1]

1

votes
2

answer
928

Views

Changing B2C Reply URL from “signin-oidc” to something else does not work

I am trying to get a ASP.NET Core 2.1 web app running with Azure AD B2C. I have this running after much reseach (and more trial and error) as the instructions found in the docs are a little off. The sign-in/sign-up process works using the default scaffolding during the project setup wizard, plus the...
John
1

votes
2

answer
699

Views

asp.net core hosted service sleeps after api inactivity

I have a hosted service that checks an email account every minute. I also am using MVC with Web API 2.1. In order to get my hosted service to start, I have to 'wake it up' by calling API methods. After a period of inactivity from the Web API the hosted service goes to sleep and stops checking the...
Cindy Hoskins
1

votes
1

answer
528

Views

ASP.NET Core: IConfigurationBuilder Does Not Contain Definition For AddAzureKeyVault

I am upgrading my ASP.NET Core web app to .NET Core 2.1, but am getting the following error: IConfigurationBuilder Does Not Contain Definition For AddAzureKeyVault This code works in .NET Core 2.0. It looks like a library is missing in .NET Core 2.1. using System; using Microsoft.AspNetCore; using M...
Brandon Minnick
1

votes
1

answer
95

Views

.net core web api app with https in docker

I have the simplest possible Web Api app in .net core ( with the default api/values api you get upon creation) I've enabled HTTPS so in debug it works, and kestrel reports: Hosting environment: Development Now listening on: https://localhost:5001 Now listening on: http://localhost:5000 When I run...
Greg Balajewicz
0

votes
0

answer
12

Views

Recaptcha host and request host do not match. Forgery attempt

I'm trying to implement reCAPTCHA.AspNetCore 2.1.1 nuget package in my project, everything is configured, I created google captcha sites with both, v2 invisible and V3 to check because I need captcha works invisible: label: SicotX domain: localhost Version: v2 invisible label: localhost domain: loca...
0

votes
0

answer
12

Views

Convert Dictionary to ICollection in Entity Framework Core

Here I am stucked with the conversion of dictionary to Icollection in EF Core. I have Dictionary in FlatEmployee class in which I am storing list of key, value pair in database. I have declared like this: public class FlatEmployee { public int EmployeeId { get; set; } public Dictionary PayAndAllowan...
Iswar
1

votes
3

answer
992

Views

Custom implementation of ILogger

In my project I often add prefixes to my log messages. Currently I am doing this with logger.LogDebug(prefix + ' some message'); I thought it would be a good way to implement a custom logger where I set the prefix and the logger itself attaches it every time it logs something. So I created my custo...
monty
1

votes
3

answer
610

Views

Create text file and download without saving on server in ASP.net Core MVC 2.1

I've found a way to create a text file then instantly download it in the browser without writing it to the server in regular ASP.net: Create text file and download The accepted answer uses: using (StreamWriter writer = new StreamWriter(Response.OutputStream, Encoding.UTF8)) { writer.Write('This is t...
niico
1

votes
1

answer
44

Views

.NET Core 2.1 - Entity Framework: Check for duplicates before adding to DB

In my SQL Server DB, I have a table of IOT data (nearing 1,000,000 records). When the app receives inbound readings, I want to check that the DB doesn't already have a reading for that device with the same timestamp. What is the fastest way to check for records with matching properties? Model public...
JED
1

votes
1

answer
1.2k

Views

How to mock the new HttpClientFactory in .NET Core 2.1 using Moq

.NET Core 2.1 comes with this new factory called HTTPClientFactory, but I can't figure out how to mock it to unit test some methods that include REST service calls. The factory is being injected using .NET Core IoC container, and what the method does is create a new client from the factory: var clie...
Mauricio Atanache
1

votes
0

answer
231

Views

Can't read HttpContext body in .net core 2.1

I have a .net core midleware where i write to the HttpContext body and then i would like to read the body but it dosent work. I am using .net core version 2.1.0-preview1-final. First i write to the response: await context.Response.WriteAsync('Test string'); And then i would like to read the response...
EdwardB
1

votes
1

answer
200

Views

How to use Razor Class Library from a Webforms Web Application Project

As part of migration process I would like to use Razor Class Library in a WebForms project. Is it possible? Testing scenario A solution with three projects (created by Visual Studion 2017 15.7.2): Project CoreLibraryTest: Razor Class Library (Core 2.1, Target Framework 4.7.1) Project RazorPages: AS...
IvanH
1

votes
0

answer
273

Views

SignalR: Throwing HubException on server and getting the error message on typescript client

Starting the connection client-side: ngOnInit() { this._gameKey = parseInt(this._route.snapshot.paramMap.get('game-key')); this._hubConnection = new HubConnectionBuilder() .withUrl('http://localhost:5000/match').build(); this._hubConnection.on('Connected', (data) => {this.connected(data)}); ... this...
Arhire Ionut
1

votes
0

answer
135

Views

Who insert Angular scripts in ASP.NET Core Angular template project

I created a new ASP.NET Core 2.1 Angular project. What is interesting is that there is index.html file inside ClientApp/src which is hosted as default page. I would like to know, which code triggers that index.html is served by default? In my old application from universal template Controllers an...
Makla
1

votes
1

answer
364

Views

NLog Custom Target fails in Azure .NET Core 2.1

I've been using NLog with .NET Core 2.0 and a custom target to write to Azure Blob storage successfully for a while. I've now upgraded to .NET Core 2.1 and the deployed solution to an Azure Web App fails because, according to the Kudu Event Log, NLog cannot find the custom target defined in the NLog...
GrahamB
-1

votes
0

answer
15

Views

two models in one controller to insert data on ASP.Net Core

how to insert data using two models on one controller. I still have difficulties when rendered to the view form.
Deri Triadi Putra
1

votes
0

answer
22

Views

Why do I get correct join with one table and not another when using VS 2017 and .net core 2.1

Disclaimer: I'm a newbie to Razor Pages and MVC but I'm very familiar with related databases (MS Access) and have a basic knowledge of SQL. I have three tables in a Razor Pages Core 2.1 Database-First solution with VS 2017. The models are Advertisement, State, and AbbrvXref. Advertisement and Sta...
John Thurow
1

votes
0

answer
143

Views

Trusting a certificate signed by a local CA from an AspNetCore-Api inside docker

I have the following scenario: I want to run three services (intranet only) in windows docker containers on a windows host an IdentityServer4 an Api (which uses the IdSvr for authorization) a Webclient (which uses the api as Datalayer and the IdSvr for authorization) All three services are running w...
emuuu
1

votes
0

answer
99

Views

How to generate a stand-alone React app project in Visual Studio?

I am building a ASP.NET Core 2 API with a administration UI in React. I don't want to mix the API and the UI in the same project (1) but I do want to include the React app as a standalone project within the solution so it gets built by Visual Studio. Doing a 'mixed' ASP.NET Core 2 + React project is...
Victor
1

votes
1

answer
331

Views

Bug or misconfigured? ASP.NET Core 2.1 firing 404 error on Access Denied

I am not sure if I found a bug, or if I just messed up the configuration some how. I have an ASP.NET Core 2.1 Razor website using AzureADB2C authentication, utilizing the new 'pre-packaged' configuration utilities). When I try to access a page that my test user doesn't have access to, it returns a...
Jerry Esch
1

votes
1

answer
864

Views

ASP.NET Core 2.1 MVC - Model Binding - Dropdown List Value

I have a ViewModel something like this which contains two properties. UserSelectedState - String value ListOfStateNames - This is a List of SelectListItem. I am able to bind the model to the View and the user sees the list of state names and makes one selection. I am posting it back to the controlle...
Adam
1

votes
1

answer
221

Views

ASP .Net Core 2.1 API Template with role based authorization

I wanted to create an ASP .Net Core 2.1 REST server. For that I created a new project and choosed the 'API' Template. I got it working with Entity Framework, a simple SQlite database and some GET and POST calls. Now I'd like to add authorization (role based) to the API. I read about the Identity stu...
ReVoluti0n_
1

votes
1

answer
143

Views

ASP.NET Core Web API multiple actions with the same action verb but different signature

Let's say I have [HttpPost] public ActionResult Login([FromBody]LoginViewModel loginViewModel) { .... } [HttpPost] public ActionResult Logout() { .... } in the same controller. And I am getting AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all...
john
1

votes
1

answer
189

Views

UNC path is invalid when starting ASP.NET Core Application in IIS

I have a shared drive on my local network \hostname\shared\resource. I have mounted the drive programattically from within the Asp.net core web application in the startup.cs file. app.UseStaticFiles(); app.UseFileServer(new FileServerOptions{ FileProvider = new PhysicalFileProvider(@'\\TS3410D618\N...
ntraylor
1

votes
0

answer
486

Views

SignalR SSE handshake fails

Hosting a ASP.Net Core 2.1 webapi and an Angular 6 webapp on 'Windows Server 2008 R2' under the same domain name but different ports (:81 and :80 respectively); not contained within the same folder. According to this article, SSE is the (standard) fallback when Websockets are unavailable, which is e...
H3katonkheir
1

votes
0

answer
47

Views

Multiple Implementation of service interface for different API controllers Autofac

I have many api controllers that have IService and ILog interface, and some more as constructor parameter. IService have different implementation: public interface IService { void Process(); } DefaultService : IService and CallService : IService as an example. I created two api controllers, DefaultC...
ash
1

votes
0

answer
147

Views

Error: Implementing AntiCrossSiteForgery POST Request from Angular6 to ASP.NET Core 2.1

Good day, I'm receiving a 400 bad request while sending post request on my ASP.NET Core Web API 2.1. I have 2 projects. First is Angular6 as my rest client and second is my ASP.NET Core 2.1 Web API as my rest server. To show you what I've done, here is my angular spa codes: I have a method that fe...
jsonGPPD
1

votes
0

answer
86

Views

Log configuration changes in ASP.NET Core 2

I want to log when configuration is changed. I do this in Program.cs or Startup.cs: ChangeToken.OnChange( () => configuration.GetReloadToken(), state => logger.Information('Configuration reloaded'), (object)null ); But I get double change reports, so it needs to be debounced. The advice is to do thi...
lonix
1

votes
0

answer
215

Views

Error on Inherit Startup in ASP.NET Core 2.1 Functional Tests

I created a project functional testing in ASP.NET Core 2.1 and xUnit. I have a function CreateServer() like this: public TestServer CreateServer() { var path = Assembly.GetAssembly(typeof(TScenarioBase)) .Location; var hostBuilder = new WebHostBuilder() .UseContentRoot(Path.GetDirectoryName(path)) ....
Vietprogrammer
1

votes
0

answer
73

Views

Async queue polling and Dependency Injection

We are building a microservices platform that will accept REST API traffic and processes messages from an internal async queue for inter-container communication. We are using the built in dependency injection for controllers and that works well, but I am wondering how to manage dependency injection...
Cale
1

votes
0

answer
133

Views

Why is Azure app service not reliably reading my connection strings when I am using the production (base app service) slot

I have an ASP.NET Core 2.1 API that I am deploying to an Azure App Service. I use Azure SQL Server for my backing databases. Below is a screenshot of the App Service (base) Application Settings blade. This shows the .Net Framework version set to 4.7. I have the App Service set up with deployment slo...
whiskytangofoxtrot
1

votes
0

answer
82

Views

list.Clear() vs new List<>() - ASP.NET Core - Entity Framework Core - Lazy loading

After some time investigating why my navigation property gets filled up again with the entities that I just removed (using entity.NavigationPropertiesCollection = new List()), I realised that with entity.NavigationPropertiesCollection.Clear() everything works fine. My question is why does Entity Fra...
john
1

votes
2

answer
519

Views

aspdotnet core project build fail on new machin

Hi I am facing a strange problem, I have create a asp.net core 2.1 web project, it works/build fine on my machine. Then I have zipped the project folder with .sln file and moved it to new machin, this also have visual studio 2017, .net core 2.1(it is a VM). I open the project and when build I get: E...
user614946
1

votes
2

answer
2.6k

Views

“500 - Internal server error” when calling ASP .Net Core 2.1 Web API on Windows Server

I have an ASP .Net Core 2.1 Web API which I've deployed to a new server we recently purchased (running Windows Server 2016 Standard). The API works perfectly on both my development PC and our old server (running Windows Server 2012 R2). But on this new server, I get this error: 500 - Internal server...
Fabricio Rodriguez
1

votes
1

answer
267

Views

webpack not found in package.json for asp.net core 2.1 with Angular project

In VS 2017 15.8.3 I create an ASP.net Core 2.1 with Angular. I do not see webpack in package.json and no webpack.config.js. but I do see this in ASP.net Core 2 with angular. Is this on purpose? do i have to configure webpack for asp.net core 2.1.
kumar
1

votes
1

answer
93

Views

Handling Auto Model Validation

I'm having a problem in which whenever I input a string request for a integer and boolean data type. I'm having a weird error messages, caused by the NET CORE2.1 new feature Auto model validation. Here is the request { 'EmailAddress' : '[email protected]', 'EmailAddressConfirm' : '[email protected]
keysl
1

votes
0

answer
382

Views

Error connecting to https://localhost:5002/.well-known/openid-configuration

I am using Identity Server 4 and ASP.NET Core 2.1. I have an API and an Auth application and tried to following: var discoveryClient = new DiscoveryClient('https://localhost:5002'); discoveryClient.Policy.RequireHttps = true; var discovery = await discoveryClient.GetAsync(); if (discovery.IsError)...
Miguel Moura
1

votes
0

answer
155

Views

FreeText in EF2.1: The 'FreeText' method is not supported because the query has switched to client-evaluation.

I'm trying to do simple fulltext search: var dbquery = _dbContext.Contents .Where(c => EF.Functions.FreeText('Content', 'a')); var result = dbQuery.ToList(); but I'm getting: InvalidOperationException: The 'FreeText' method is not supported because the query has switched to client-evaluation. Inspec...
Liero
1

votes
0

answer
120

Views

Add Identity Authentication to Identity Server Front end

I've created an Identity Server 4 project which runs our Identity server and I have created a front end to the project so we can maintain it. The problem I am running into is it looks like I cannot have Identity Server middleware and use Identity Authentication in the same project. Is there a way...
Andy Xufuris
1

votes
0

answer
29

Views

Using .Net Core to render Webpages similary to Node and Express and a view engine

I've been playing around with .net core 2.1 and I am trying to get a better understanding of the server architecture that it runs. I am trying to use it in a similar way to how Node and Express can be used to render views based on http requests. Kind of like this: router.get('/events', function(re...
mo_maat

View additional questions