Questions tagged [asp.net-core-2.0]
Use this tag for questions specifically related to ASP.NET Core 2.0, in addition to using the 'ASP.NET Core' tag.
4,178
questions
245
votes
5
answers
214k
views
Cannot resolve scoped service from root provider .Net Core 2
When I try to run my app I get the error
InvalidOperationException: Cannot resolve 'API.Domain.Data.Repositories.IEmailRepository' from root provider because it requires scoped service 'API.Domain....
175
votes
4
answers
86k
views
Use multiple JWT Bearer Authentication
Is it possible to support multiple JWT Token issuers in ASP.NET Core 2?
I want to provide an API for external service and I need to use two sources of JWT tokens - Firebase and custom JWT token ...
120
votes
10
answers
142k
views
How to use Bootstrap 4 in ASP.NET Core
I want to update Bootstrap in ASP.NET Core with NuGet. I used this:
Install-Package bootstrap -Version 4.0.0
It did add the dependencies but how do I add it to my project now? What is the path for ...
115
votes
30
answers
132k
views
Unable to create migrations after upgrading to ASP.NET Core 2.0
After upgrading to ASP.NET Core 2.0, I can't seem to create migrations anymore.
I'm getting
"An error occurred while calling method 'BuildWebHost' on class
'Program'. Continuing without the ...
112
votes
5
answers
236k
views
No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization
I have a .NET Core 2.0 app and have a problem with authorization. I want to use custom authorization with special requests. Header and standard default authentication.
First, I add configuration in ...
105
votes
2
answers
70k
views
How to do DI in asp.net core middleware?
I am trying to inject dependency into my middleware constructor as follows
public class CreateCompanyMiddleware
{
private readonly RequestDelegate _next;
private readonly UserManager<...
102
votes
4
answers
66k
views
IServiceCollection does not contain a defintion for AddHttpClient
I am trying to use HttpClient in my .net core 2.0 project and for that I have injected HttpClient in my controller. But when I am trying to configure httpclient in my startup.cs I am getting this ...
98
votes
8
answers
108k
views
Call SignalR Core Hub method from Controller
How can I call SignalR Core Hub method from Controller?
I am using ASP.NET Core 2.0 with Microsoft.AspNetCore.SignalR (1.0.0-alpha2-final).
I have windows service which communicate with Excel, ...
97
votes
2
answers
72k
views
ASP.NET Core 2.0 authentication middleware
With Core 1.1 followed @blowdart's advice and implemented a custom middleware:
https://stackoverflow.com/a/31465227/29821
It worked like this:
Middleware ran. Picked up a token from the request ...
95
votes
4
answers
18k
views
How do I get a console project to group my appsettings.json files?
If I start a new web api project, the appsettings files are grouped together. However, I'm creating a working project from the console app template and when I create the appsettings files manually, ...
92
votes
6
answers
42k
views
Identity in ASP.Net Core 2.1< - Customize AccountController
I have installed ASP.NET Core 2.1 but even though I have created a new ASP.NET Core Web Application using ASP.NET Core 2.1 with Individual User Accounts → Store user accounts in-app I can't find the ...
91
votes
1
answer
57k
views
AddDbContext or AddDbContextPool
For Asp.net Core apps, which one do we have to use? AddDbContext or AddDbContextPool? According to EF Core documentation, AddDbContextPool provides high performance but the default Asp.net Core ...
89
votes
2
answers
60k
views
FromUri in ASP.NET CORE 2.0
This question is because in my MVC project with ASP.NET CORE 2.0, I can not add the [FromUri] attribute to my drivers.
I tried using libraries like System.Web.Http, but I did not recognize them. Then ...
88
votes
3
answers
53k
views
What is the difference between UseStaticFiles, UseSpaStaticFiles, and UseSpa in ASP.NET Core 2.1?
ASP.NET Core 2.1.1 offers several seemingly related extension methods for appBuilder:
UseStaticFiles from Microsoft.AspNetCore.StaticFiles
UseSpaStaticFiles from Microsoft.AspNetCore.SpaServices....
84
votes
10
answers
298k
views
instance of entity type cannot be tracked because another instance with same key value is tracked [closed]
I'm using generic repository pattern in asp.net core 2.0 which can not dispose repository object, when I am going to update the entry its updated for one time successfully but when I am trying to ...
74
votes
4
answers
61k
views
What exactly is 'UseAuthentication()' for?
I have a question regarding authentication in ASP.NET Core 2: what exactly is the call app.UseAuthentication() for?
Is it a basic prerequisite so that I can implement my custom authentication logic? ...
72
votes
13
answers
61k
views
Trying to add AutoMapper to Asp.net Core 2?
I worked on a asp.net core 1.1 project a while ago and use in projetc AutoMapper.
in asp.net core 1.1, I add services.AddAutoMapper() in startup file :
StartUp file in asp.net core 1.1:
public ...
71
votes
1
answer
75k
views
Cascade deleting with EF Core
I am having a few issues with EF Core at the moment. I have some data that I need to delete, and I am struggeling to see how the fluent API works, exactly in regards to the .OnDelete() function.
...
70
votes
1
answer
59k
views
What is the difference between IWebHost WebHostBuilder BuildWebHost
After reading Microsoft documents I am still confused. I need to deploy a .net core 2 web application I developed to an IIS server and I can't get a straight forward answer on anything. This is just ...
65
votes
9
answers
115k
views
How to use log4net in Asp.net core 2.0
I configure log4net in my asp.net core 2.0 application as mentioned in this article LINK
program.cs
public static void Main(string[] args)
{
var logRepository = LogManager.GetRepository(...
65
votes
5
answers
45k
views
ASP.NET Core docker build error
I'm new to ASP.NET Core and docker.
I've created a simple ASP.NET Core 2.0 app and try to use docker with it on Windows. However, I get this error:
Your Docker server host is configured for 'Linux', ...
65
votes
4
answers
48k
views
Run a background task from a controller action in ASP.NET Core
I am developing a web application with a REST API using C# with ASP.NET Core 2.0.
What I want to achieve is when the client send a request to an endpoint I will run a background task separated from ...
63
votes
2
answers
95k
views
How to use HTTPS / SSL with Kestrel in ASP.NET Core 2.x?
I am currently using ASP.NET Core 2.x and I used to be able to get Kestrel to to use HTTPS / SSL by simply putting it in the UseUrls() method like so:
var host = new WebHostBuilder()
.UseUrls("...
59
votes
1
answer
44k
views
System.InvalidOperationException: 'A path base can only be configured using IApplicationBuilder.UsePathBase().' [duplicate]
I have an ASP.Net Core 2 Solution running in Docker which is working fine on 1 machine the is running VS 2017 Professional but on another machine running VS 2017 Community I am getting the following ...
58
votes
5
answers
68k
views
Httpclient This instance has already started one or more requests. Properties can only be modified before sending the first request
I am creating an application in .Net Core 2.1 and I am using http client for web requests. The issue is I have to send parallel calls to save time and for that I am using Task.WhenAll() method but ...
57
votes
6
answers
88k
views
How do I setup multiple auth schemes in ASP.NET Core 2.0?
I'm trying to migrate my auth stuff to Core 2.0 and having an issue using my own authentication scheme. My service setup in startup looks like this:
var authenticationBuilder = services....
57
votes
3
answers
21k
views
Can the new csproj file structure be used with a ASP.NET Framework project?
The new .csproj format includes some significant improvements over the classic files, including tight integration with NuGet package management and significantly less-verbose structure. I want to gain ...
55
votes
5
answers
72k
views
Accept x-www-form-urlencoded in Web API .NET Core
I have a .NET Core Web API that is returning a 415 Unsupported Media Error when I try to post some data to it that includes some json. Here's part of what is returned in the Chrome Debugger:
Request ...
52
votes
2
answers
15k
views
IWebHost: Calling Run() vs RunAsync()
When a new ASP.NET Core 2.0 project is created, the boilerplate Main method in the Program class looks something like this:
public static void Main(string[] args)
{
BuildWebHost(args).Run(); // ...
50
votes
11
answers
62k
views
AddIdentity() fails "InvalidOperationException: Scheme already exists: Identity.Application"
I'm trying to add facebook login to my .NET Core 2.1 site
I'm following this , guide and more specific, this (for facebook login)
After have adding the lines below to startup.cs, inside ...
50
votes
4
answers
61k
views
Correct way to return HttpResponseMessage as IActionResult in .Net Core 2.2
In .Net Core 2.2. I am creating a API Controller that routes the request to another Http endpoint based on payload.
[Route("api/v1")]
public class RoutesController : Controller
{
...
49
votes
7
answers
63k
views
The provider for the source IQueryable doesn't implement IAsyncQueryProvider
I have some codes like below, I want to write unit tests my method. But I'm stuck in async methods. Can you help me please ?
public class Panel
{
public int Id { get; set; }
[Required] ...
48
votes
5
answers
74k
views
'HttpPostedFileBase' in Asp.Net Core 2.0
I'm recently working on a ReactJS app that's calling an API (developed with .NET Core 2.0).
My question is how to use HttpPostedFileBase in an .NET Core 2.0 API in order to get file content and ...
48
votes
3
answers
23k
views
Override array settings in appsettings.json with those in appsettings.Production.json
I'm using ASP.NET Core 2.1. I have settings in appsettings.json and I bind them to classes using the options pattern. I want to override some of them in appsettings.Production.json.
Overriding is ...
45
votes
5
answers
58k
views
Entity Framework Scaffold-DbContext Login failed for user
I am trying to build an API using Visual Studio 2017 and .NET Core 2 with Entity Framework Core. I am following the directions from This Link. I am on the section titled: Reverse engineer your model
...
43
votes
7
answers
20k
views
ASP.NET Core 2.0 combining Cookies and Bearer Authorization for the same endpoint
I've created a new ASP.NET Core Web Application project in VS17 using the "Web Application (Model-View-Controller)" template and ".Net Framework" + "ASP.NET Core 2" as the configuration. The ...
42
votes
5
answers
25k
views
How to access current HttpContext in ASP.NET Core 2 Custom Policy-Based Authorization with AuthorizationHandlerContext
How can I access current HttpContext to check for route and parameters inside AuthorizationHandlerContext of Custom Policy-Based Authorization inside ASP.NET Core 2?
Ref example: Custom Policy-Based ...
41
votes
2
answers
29k
views
Increase upload request length limit in Kestrel
I am running an ASP.NET Core web app and want to upload large files.
I know that when running IIS, the limits can be changed via web.config:
<httpRuntime maxRequestLength="1048576" />
...
<...
41
votes
1
answer
10k
views
EF Core migrations in Docker container
I am setting up a WebApi in .NET Core 2.0. I will be using Entity Framework Core as ORM. Whole app will be deployed as Docker Container. The thing that disturbs me a bit is the way of handling DB ...
40
votes
5
answers
38k
views
Dependency injection in ASP.NET Core 2 throws exception
I receive following exception when I try to use custom DbContext in Configure method in Startup.cs file. I use ASP.NET Core in version 2.0.0-preview1-005977
Unhandled Exception: System.Exception: ...
40
votes
1
answer
25k
views
How to set multiple audiences in Asp.Net Core 2.0 "AddJwtBearer" middleware?
I have an Asp.Net Core 2.0 WebApi which is authenticating against AAD:
services.AddAuthentication(options => { options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; })
...
40
votes
4
answers
29k
views
Getting IConfiguration from ServiceCollection
I´m writing my own extension method for ServiceCollection to registered the types of my module and I need to access the IConfiguration instance from the collection to register my Options.
Extension ...
39
votes
10
answers
130k
views
AADSTS50011: The reply url specified in the request does not match the reply urls configured for the application: '<AppId>'
I have a .NET Core 2 app template that is configured to use Azure AD out of the box.
The configuration is:
{
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "...
38
votes
3
answers
40k
views
How to replace AddJwtBearer extension in .NET Core 3.0
I have the following code which compiles and works in .NET Core 2.2:
byte[] key = Encoding.ASCII.GetBytes(Constants.JWT_SECRET);
services.AddAuthentication(x =>
{
x....
37
votes
3
answers
27k
views
Remove console and debug loggers in ASP.NET Core 2.0 when in production mode
In ASP.NET Core 2.0 we have this
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
That ...
37
votes
3
answers
33k
views
How to unique identify each request in a ASP.NET Core 2 application (for logging)
In a ASP.NET Core 2 application, I need a unique identifier (e.g. Guid) for each request so I can include that id in each log and understand the sequence of logs of each request.
This is not hard to ...
35
votes
5
answers
78k
views
How To Disable Https in Visual Studio 2017 Web Proj ASP.NET Core 2.0
I've created a default project in Visual Studio 2017 with ASP.NET Core 2.0. I've chosen the Web App with MVC and with Individual Use Auth. By default, it is coming up configured and working with ...
35
votes
6
answers
55k
views
Execute SQL command in Entity Framework Core 2.0 to delete all data in a table
I want to execute an SQL command from Entity Framework Core 2.0, but I can't figure out how to do so.
1.- The reason why I need to, is that I want to delete all data from a database table, and using ...
35
votes
1
answer
13k
views
Json Format for a TimeSpan that can be bound using Microsoft.Extensions.Configuration
In a project I need to configure some third party library via the Micorosoft.Extensions.Configuration.
The library gives an options class and I used the configurationSection.Bind(optionsClassInstance)...
35
votes
9
answers
14k
views
Asp.Net Core 2.0 on Azure results in a 502.5
I have a small web app developed with Asp.Net Core 1.1 deployed on Azure and it works well. I just migrated the project to use Asp.Net Core 2.0 and tried to deploy it on Azure. The deployment went ...