Questions tagged [asp.net-core-middleware]

17585 questions
1

votes
1

answer
41

Views

Dependency Injection: No Service for type

I'm trying to separate the concerns across my application and I thought this answer by Steven fits my scenario beautifully but I'm trying to remove the ninject element: Validation: How to inject A Model State wrapper with Ninject? I've added all required classes from the answer. I've got my service...
Smithy
1

votes
3

answer
39

Views

edit only changed or mentionned values with entity framework core

I need to update only mentioned fields in the put request body , the current issue is that all the values that are not mentioned in the entity to update are set to null below is my currrent update implementation in the generic repository. public virtual void Update(T entity) { Context.Attach(entity...
Jawhar Jarrar
1

votes
2

answer
38

Views

Problem with special characters from aspnet core to javascript

I am trying to pass an error message through the ModelState dictionary to be fed to a javascript code that generates an alert with that error. Everything works, but I can't get the special characters to appear correctly like ' ' ' and 'è'. Solutions? Code AspNet Core: ModelState.AddModelError('Uten...
Elmoro
1

votes
1

answer
17

Views

Why PartialAsync doesn't call coresponding controller method?

I have a .NET Core 2.1 MVC application. I have a Home controller that looks like this: public class HomeController : Controller { public IActionResult Index() { return View(); } public IActionResult CountView(MyModel model) { ... return PartialView(model); } } In the Index view I want to display a p...
Szybki
-1

votes
1

answer
21

Views

How Can used HttpClient in asp.net core 2.2 to get data from url in share host?

I'm writing asp.net mvc core 2.2 also I need to get data from another web server with Http or Https. How can I do this I wrote code to using HttpClient in my code? my program is a Telegram Bot and I wrote this to get url from telegram and after checking and validating that I call url with HttpClient...
Faraz
0

votes
0

answer
7

Views

How can I read a file which will be upload from a form in .Net Core API?

I create a method in my .Net Core API which will upload a file. [HttpPost] public async Task ReadFile(IFormFile file) { return BadRequest(file); } I do a return BadRequest(file) in order to read what it send me on postman. The result is this : { 'contentDisposition': 'form-data; name=\'file\'; filen...
user10863293
-1

votes
0

answer
14

Views

Download file into FIleStream from a web page url

I am trying to download a xlsx into FileStream from a url, which doesn't directly points to download file (ex: example.com/file.xlsx), but downloads file using js download function. I am trying to achieve this by creating a HttpWebRequest and getting the response stream like this: var fs = File.Crea...
Pratik
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
1

answer
6

Views

ASP.NET Core Razor: Conditional attribute without value

I want to conditionally render a readonly attribute in an . In the ASP.NET Core dialect of Razor the interpretation of attributes is a little different opposed to System.Web.Mvc. In System.Web.Mvc I used to do: In ASP.NET Core, the same does not work: no error, but the attribute isn't rendered eithe...
Sebazzz
1

votes
0

answer
10

Views

ASP.NET Core model binding behaviour switch

During some heavy refactorings of an API it seems I changed something effecting the model binding / model validation behaviour. I tried to investigate the changes I can't figure out what the change caused. I have a MyApiController inheriting from ControllerBase. MyApiController has a post method re...
monty
0

votes
0

answer
18

Views

How to integrate Social Login with existing .Net core Web API backend and Angular SPA frontend with working OpenIddict user/password and bearer token

TL;DR Question: how to implement social login (OAuth2 authorization flow) with an existing SPA/Web API application that is based on identity, user/password, bearer token authentication? I have an existing application that has: Backend: .Net Core 2 Web API with Identity and OpenIddict services config...
Fernando Ribeiro
0

votes
0

answer
42

Views

Why is GET date correct but incorrect in POST?

Using Reactjs with Axios to post/get to a dotnetcore webapi. Axios GET api call to retrieve a list of datetimesUTC 1a. Response datetimeUTCs are clearly correct in console/display. Axios GET api call passes in the selected datetimeUTC 2a. The API clearly receives the correct UTC datetime Axios POST...
DateTimeSucks
0

votes
2

answer
11

Views

Model's indexes doesn't validate

Table in postgres: CREATE TABLE 'public'.'filters' ( 'Id' int4 NOT NULL DEFAULT nextval(''filters_Id_seq''::regclass), 'Name' varchar(200) COLLATE 'pg_catalog'.'default' NOT NULL DEFAULT ''::character varying, 'Type' int4 NOT NULL, 'Alias' varchar(200) COLLATE 'pg_catalog'.'default' NOT NULL DEFAULT...
TrueGameover
1

votes
0

answer
21

Views

ASP.NET Core 2.2 Integration Testing DbContext Service not registered

Setup Windows 10 Visual Studio Professional 2017 v15.9.9 ASP.NET Core 2.2 EF Core 2.2 Dapper xUnit 2.4.1 Description I'm using the WebApplicationFactory from the Microsoft.AspNetCore.Mvc.Testing package to setup my integration tests. I've been following the official documentation to customise the we...
GreenyMcDuff
-1

votes
0

answer
20

Views

Receiving incorrect object values after deserializing JSON into IEnumerable in MVC Controller

I'm trying to deserialize some JSON into a IEnumerable (below). However, the DtoWrapper.Dto properties inside the IEnumerable are always of type BaseDto - but without the posted values in the resulting collection. Scratching my head a bit. Might be a bit clearer with some code, any help greatly app...
Kiada
0

votes
0

answer
25

Views

How to keep DbContext in Connected state with Web API

Since Web APIs are stateless when you have EF Core backend after any request the DbContext would be disconnected. Therefore we have made QueryTracking as NoTracking since default behavior TrackAll doesn't give any benefit since its a web application DbContext.ChangeTracker.QueryTrackingBehavior = Q...
Nipuna
0

votes
0

answer
18

Views

How to solve error unprotecting the session cookie

I am getting the following warnings, AFAIK this is related to cookies and GDPR, please CMIIW.. how to solve this? need help.. thanks a lot in advance Regards Don public void ConfigureServices(IServiceCollection services) { services.Configure(options => { options.CheckConsentNeeded = context => true;...
Donald
1

votes
2

answer
1.6k

Views

Do I use Snapshot file, migration file or data annotations in my EF Core to update database?

I'm trying to understand the different types of migration paths we can choose when developing an ASP.NET Core 1.0 application with EF Core. When I created my first Core application I noticed it generated a ApplicationDbContextModelSnapshot class that uses a ModelBuilder to build the model. Then I r...
Ray
0

votes
0

answer
16

Views

UsedRange in ASP.Net

I have this codes, FileInfo filepath = new FileInfo(path); using (ExcelPackage package = new ExcelPackage(filepath)) { ExcelWorksheet workSheet = package.Workbook.Worksheets['Sheet1']; int totalRows = workSheet.Dimension.Rows; List questionsList = new List(); for (int i = 2; i
Chris May
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
0

votes
0

answer
5

Views

How do I use data-* attributes with Html.DropdownListFor helper?

I'm trying to create a dropdown list (using bootstrap-select) with different data-subtext attributes on each option. The thing is, when I use tag helper, it automatically creates validation tags (which is great) but forbids me from using any data-* attributes on select list options. Creating option...
Ilya Bezus
1

votes
0

answer
6

Views

Auth0 + Swashbuckle .Net Core 2.2. Missing claims in jwt token when using SwaggerUI

I am making a ASP.Net Core WebApi which is authentication via Auth0. I am using Swagger and SwaggerUI and trying to authenticate from Swagger UI. // Add authentication services services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; option...
Tonven
1

votes
2

answer
1.5k

Views

How to perform a join in c# .net core Entity Framework using

I have this relation ship. In both of this model I have a navigation properties, however I still don't know how to use them. The Customer Model public class Customer { public int Id { get; set; } [Required] public string FirstName { get; set; } [Required] public string LastName { get; set; } [Requi...
user3862830
1

votes
1

answer
1.8k

Views

Get a service in a IServiceCollection extension

I have this extension public static class ServiceCollectionExtensions { public static IServiceCollection MyExtension(this IServiceCollection serviceCollection) { ... } } and I need to get information from a service like this: services.AddAuthentication(options => { options.DefaultAuthenticateScheme...
andres descalzo
1

votes
2

answer
4.1k

Views

ef core migration insert data

I'd like to insert data into table in migration. Is it possible? Migration needs parameterless constructor available and I'd like to use db context defined in Startup.cs file (best I'd like to get it throught dependency injection). How do that?
Marek
1

votes
1

answer
905

Views

Trying to host .NET core 2.1 web app in window service creates dll instead of exe

Following the instructions here I: installed visual studio 2017 preview installed .NET Core 2.1 RC1 dotnet add package Microsoft.AspNetCore.Hosting.WindowsServices --version 2.1.0-rc1-final new project -> select .NET Core on the left -> select ASP.NET Core Web Application -> select ASP.NET Cor...
kofifus
1

votes
1

answer
767

Views

Missing required argument '<PROVIDER>'. Scafffold Dbcontext in asp.net core 2.1.MAC

Trying to do Scaffold with the existing database in mac os visual studio using terminal. Here is the command for the scaffold dotnet ef dbcontext Scaffold 'Server=;Initial Catalog=;Persist Security Info=False;User ID=;Password=;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=Fal...
San Jaisy
1

votes
3

answer
3.3k

Views

Mapper not initialized. Call Initialize with appropriate configuration

I get error when usinng AutoMaper for netcore 2.1 projet Mapper not initialized. Call Initialize with appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you do not have any calls to the static Mapper.Map methods, and if you're using Proje...
ltiendat95
1

votes
1

answer
846

Views

Net core MVC clean architecture without repository pattern

I'm trying to create a MVC application in net core 2.1 using the eshoponweb example application. Ive read that in entity Framework core there's no great benefit of putting a repository layer in and to just use the ef dbcontext directly. How would I do this in a clean architecture scenerio. In the ex...
JimmyShoe
1

votes
1

answer
648

Views

asp.net core select validation with data annotation not working

I have spent a remarkable amount of time to find out but I couldn't. When I post my model without selecting any option - in fact selecting 0 - Select - option, the Required validation is not working. I also tried removing the programatically added default option from service code to the view code,...
ibubi
1

votes
2

answer
336

Views

asp-for in checkbox throws and error in asp.net core

Here i have used two checkbox Send Report Send Invoice and data type for both checboc i.e asp-for='SendReport' and asp-for='SendInvoice' is bit. Now the problem is that when ever i try to load the page its throws error as below Unexpected 'asp-for' expression result type 'System.Nullable`1[[System.B...
redcaper71
1

votes
2

answer
877

Views

Access ASP.NET Core 2.1 web app hosted on localhost from mobile device

I create an out of the box asp.net core 2.1 web app with react. When I run it, it hosts on localhost:(some port). I want to access that on my mobile device. I tried accessing it from local host by adding the port to the Inbound Rules on Windows Defender Firewall.It didn't work so I wanted to change...
Firas Al-Husari
1

votes
1

answer
884

Views

Can't get rid of missing manifest.json error

I'm building an ASP.NET Core app with ReactJs front-end in Visual Studio 2017. Recently, I started to notice the missing manifest.json error in the console -- see below. It doesn't seem to effect my app but I do want to get rid of this error. If I view my app in Edge, I don't see the missing manifes...
Sam
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
2

answer
683

Views

SignalR Core 2.2 CORS AllowAnyOrigin() breaking change

To connect via SignalR to an ASP.NET Core 2.1 server from any origin, we had to configure the pipeline as follows: app.UseCors ( builder => builder .AllowAnyHeader () .AllowAnyMethod () .AllowAnyOrigin () .AllowCredentials () ) According to this document, ASP.NET Core 2.2 no longer allows the combin...
Alexandre
1

votes
1

answer
84

Views

How to properly use IPluralizer in IDesignTimeServices

In my app I use code-first approach and I'm adding entities to DbContext only via IEntityTypeConfiguration. My goal is to achieve pluralized table names i.e. Models for Model. After reading documentation, article, This question my understading would be that my pluralizer should be registered and as...
WueF
1

votes
3

answer
332

Views

Configuration GetSection returns null value for object sections

Hello i am using a a json configuration file within a .NET Core App and i do not understand why i get the value null for subsections that are objects: { 'tt': { 'aa':3, 'x':4 }, 'Url':333, 'Config': { 'Production': { 'RedisAddress': { 'Hostname': 'redis0', 'Port': 6379 }, 'OwnAddress': { 'Hostname':...
Bercovici Adrian
1

votes
3

answer
42

Views

API request in React

I am trying to build a .net core web app with react. However I',m struggling with some api calls and function. This may be asked before but I could not find the solution for myself. class Documents extends Component{ constructor(props){ super(props); this.state = { docs: [] }; this.deleteHandle = th...
Thanh T Dao
1

votes
1

answer
39

Views

How do I change the ILazyLoader implementation in Entity Framework Core 2.2?

I created an ASP.NET Core 2.2 Application, in Startup.cs I have this: services.AddEntityFrameworkSqlServer(); services.AddScoped(); services.AddDbContext(builder => { builder.UseLazyLoadingProxies(); builder.UseSqlServer(Configuration.GetConnectionString('DefaultConnection')); var options = builder....
Luiz Bicalho

View additional questions