Questions tagged [asp.net-core-2.2]
Use this tag for questions specifically related to ASP.NET Core 2.2, in addition to using the 'ASP.NET Core' tag.
asp.net-core-2.2
941
questions
240
votes
18
answers
124k
views
.NET Core MVC Page Not Refreshing After Changes
I'm building a .NET Core MVC on the latest version 2.2. I have a problem when I make changes to the CSHTML file and refresh the page, my changes are not reflected in the browser. I have to restart the ...
208
votes
2
answers
87k
views
IConfiguration does not contain a definition for GetValue
After moving a class through projects, one of the IConfiguration methods, GetValue<T>, stopped working. The usage is like this:
using Newtonsoft.Json;
using System;
using System.Net;
using ...
111
votes
7
answers
79k
views
Populate IConfiguration for unit tests
.NET Core configuration allows so many options to add values (environment variables, json files, command line args).
I just can't figure out and find an answer how to populate it via code.
I am ...
106
votes
39
answers
166k
views
HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure after upgrading to ASP.NET Core 2.2
After upgrading my project to ASP.NET Core 2.2, I tried to run the application (locally of course) and the browser displayed an error message like in the below screenshot.
no more errors notified by ...
96
votes
4
answers
60k
views
How to create a LoggerFactory with a ConsoleLoggerProvider?
The ConsoleLoggerProvider has four constructors:
ConsoleLoggerProvider(IConsoleLoggerSettings)
ConsoleLoggerProvider(IOptionsMonitor<ConsoleLoggerOptions>)
ConsoleLoggerProvider(Func<String,...
78
votes
28
answers
132k
views
How to fix error "ANCM In-Process Handler Load Failure"?
I'm setting up the first site in IIS on Windows Server 2016 Standard.
This is a NET Core 2.2 application. I cannot get the site to show.
I am getting this error:
HTTP Error 500.0 - ANCM In-Process ...
66
votes
7
answers
43k
views
How to fix obsolete ILoggerFactory methods?
I upgraded my project to .NET Core 2.2.x and got an obsolete warning regarding the following code - both lines:
public void Configure(IApplicationBuilder app,
...
61
votes
8
answers
186k
views
Asp.net core HttpsRedirectionMiddleware Failed to determine the https port for redirect
I am trying to host an ASP.net Core Web Application in a windows service. I am able to create a self contained deployment and created the windows service. My web application is configured to have port ...
51
votes
3
answers
22k
views
What are differences between Portable and win-x64 when deploying?
I deploy my code to IIS on Windows Server 2016 and I am trying to understand the effective difference between selecting Portable vs win-x64 in the Publish/Settings/Target Runtime dropdown.
Will the ...
41
votes
4
answers
28k
views
Why is ClaimTypes.NameIdentifier not mapping to 'sub'?
Using ASP.NET Core 2.2 and Identity Server 4 I have the following controller:
[HttpGet("posts"), Authorize]
public async Task<IActionResult> GetPosts() {
var authenticated = this.User....
38
votes
4
answers
28k
views
Asp.Net core Tempdata and redirecttoaction not working
I have a method in my basecontroller class that adds data to tempdata to display pop-up messages.
protected void AddPopupMessage(SeverityLevels severityLevel, string title, string message)
{
var ...
35
votes
6
answers
12k
views
Disable verbose logging of symbol loading in vscode debug console
When running my webapp (in vscode), the debug console is filled with lines like these:
Loaded '/foo/bar/dotnet/shared/Microsoft.NETCore.App/2.2.4/System.Private.CoreLib.dll'. Skipped loading ...
32
votes
5
answers
20k
views
Prevent redirect to /Account/Login in asp.net core 2.2
I am trying to prevent the app to redirect to /Account/Login in asp.net core 2.2 when the user isn't logged in.
Even though i write LoginPath = new PathString("/api/contests"); any ...
32
votes
3
answers
14k
views
Mock IOptionsMonitor
How can I make an class instance manually of a class that requires an IOptionsMonitor in the constructor?
My Class
private readonly AuthenticationSettings _authenticationSettings;
public ...
27
votes
5
answers
30k
views
How to validate configuration settings using IValidateOptions in ASP.NET Core 2.2?
Microsoft's ASP.NET Core documentation briefly mentions that you can implement IValidateOptions<TOptions> to validate configuration settings from appsettings.json, but a complete example is not ...
26
votes
1
answer
25k
views
How do I set "Parameter content type" using Swashbuckle?
My swagger ui shows "Parameter content type" with various entries: "application/json-patch+json", "text/json", "application/json", and "application/*+json".
I only want "application/json".
There's a ...
23
votes
4
answers
70k
views
docker is exited immediately when runs with error code 139
I have a web api project with running fine when i ran through visual studio, able to build the image also.
but when i run using the command
docker run -d -t -p 8000:83 8fbf296e2173
shows no error ...
23
votes
2
answers
12k
views
Refit Client using a dynamic base address
I am using Refit to call an API using a Typed Client in asp.net core 2.2 which is currently bootstrapped using a single BaseAddress from our configuration Options:
services.AddRefitClient<IMyApi&...
22
votes
8
answers
22k
views
Integrating HealthCheck endpoint into swagger (open API) UI on dotnet core
I am using Dotnet Core healthchecks as described here. In short, it looks like this:
First, you configure services like this:
services.AddHealthChecks()
.AddSqlServer("connectionString", ...
22
votes
1
answer
3k
views
Is reverse proxy actually needed on ASP.NET core?
We're wondering if reverse proxy is actually required for most use cases and would appreciate additional information.
The Kerstel/Nginx documentation claims:
Kestrel is great for serving dynamic ...
21
votes
3
answers
9k
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 ()
...
20
votes
6
answers
19k
views
ASP .Net Core with Razor Pages Vs Angular for UI [closed]
Our enterprise application is a massive (1000+ pages) app and primarily it is glorified data entry application. There is no major business process. All most all pages have CRUD. We are trying to re-...
19
votes
3
answers
11k
views
Select correct Angular Environment based on .Net Core build
I created an .Net Core Web Api with an Angular ClientApp with the templates from Visual Studio.
When building the project also builds the contained Angular App with the params set in the .csproj <...
19
votes
5
answers
23k
views
How to read request body multiple times in asp net core 2.2 middleware?
I tried this:
Read request body twice
and this:
https://github.com/aspnet/Mvc/issues/4962
but did not work.
I read request body like this:
app.Use(async (context, next) =>
{
var requestBody = ...
19
votes
1
answer
2k
views
ASP.NET Core 2.2 - Password reset not working on Azure (Invalid token)
I have an ASP.NET Core 2.2 application running on multiple instances on an Azure Web App; it uses EF Core 2.2 and ASP.NET Identity.
Everything works fine except the Password Reset flow where a user ...
17
votes
4
answers
18k
views
How can I get the current route name with ASP.NET Core?
I have an application that is written on the top of ASP.NET Core 2.2 framework.
I have the following controller
public class TestController : Controller
{
[Route("some-parameter-3/{name}/{id:int}...
17
votes
2
answers
4k
views
Should I dispose of X509Certificate2?
I'm using IdentityServer4 and I want to load signing certificate from file. For example,
var certificate = new X509Certificate2(
path,
password,
X509KeyStorageFlags....
16
votes
3
answers
22k
views
BadHttpRequestException: Reading the request body timed out due to data arriving too slowly. See MinRequestBodyDataRate on ASP.NET core 2.2
I'm using aspnetboilerplate solution developed with ASP.NET core 2.2 .
The backend is deployed on azure and it uses the SQL server provided.
Sometimes, when the backend has a lot of requests to handle,...
16
votes
3
answers
8k
views
Why does order between UseStaticFiles and UseDefaultFiles matter?
I understand that the order of registration for middleware may matter. However, it's not given that it's necessarily the case.
I noticed that UseDefaultFiles() needs to precede UseStaticFiles() (...
16
votes
1
answer
3k
views
Cannot use 'Microsoft.AspNet.OData.Routing.ODataRoute' with Endpoint Routing.' Exception with ASP Net Core 2.2
After upgrading the ASP NET Web API project framework to the Core 2.2 version, the OData route configuration fails. It throws "Cannot use 'Microsoft.AspNet.OData.Routing.ODataRoute' with Endpoint ...
16
votes
1
answer
2k
views
Uncompiled partial view doesn't inherit from ViewImports
I moved a part of a view into a partial view.
_ViewImports.cshtml
@using AsonCore.Helpers
@using AsonCore.Models
@namespace AsonCore.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
...
15
votes
5
answers
18k
views
InvalidDataException: Multipart body length limit 16384 exceeded
What I am trying to do:
I am attempting to upload a multipart/form-data with a file and a JSON blob using Postman to an ASP.NET Core 2.2 APIController and stream the file to a temporary file on the ...
14
votes
7
answers
39k
views
How to fix swagger.json not found in .net core 2.2 app
I'm deploying my .net core app on IIS server and facing the issue in swagger UI where swagger.json not found. When I run it locally (Development environment) everything is working perfectly but when I ...
14
votes
2
answers
10k
views
dotnet publish Error: The process cannot access the file because it is being used by another process
I get the following error when tring to run dotnet publish:
The process cannot access the file because it is being used by another
process.
This appears to happen when you try to publish your ...
14
votes
2
answers
21k
views
Authentication fails with "Unprotect ticket failed" for Asp.Net Core WebApi
When I use Bearer token with an AspNetCore controller protected with [Authorize], I get the log message:
info: Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler[7]
...
13
votes
4
answers
10k
views
AspNetCore Integration Testing Multiple WebApplicationFactory Instances?
Does any one know if it is possible to host multiple instances of WebApplicationFactory<TStartup>() in the same unit test?
I have tried and can't seem to get anywhere with this one issue.
i.e
...
13
votes
10
answers
33k
views
HTTP Error 500.30 - ANCM In-Process Start Failure error in ASP.NET Core 2.2
I am configuring this application
Confirming the account and recovering passwords in ASP.NET Core
but I have an error:
HTTP Error 500.30 - ANCM In-Process Start Failure Common causes of
this ...
13
votes
5
answers
8k
views
How to return 403 instead of redirect to access denied when AuthorizeFilter fails
In Startup.ConfigureServices() I configure authorization filter like this:
services.AddMvc(options =>
{
options.Filters.Add(new AuthorizeFilter(myAuthorizationPolicy));
})
and I use either ...
13
votes
2
answers
5k
views
Hide swagger bad response example model in net core 2.2
I upgrade my netcore 2.1 project to 2.2 and i have a problem with my swagger page.
Previously in swagger bad response it only show "Bad Request" without the model.
But after i upgraded to net core 2....
13
votes
1
answer
13k
views
Cannot implicitly convert type 'Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<T>' to 'T'
I am using ASP.NET core 2.2 for developing web apis. I have the following method in repository class:
public async Task<Articles> AddAsync(Articles article)
{
return await _context.Articles....
12
votes
2
answers
7k
views
ASP.NET Core MVC View Component search path
In the documentation here:
https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-components?view=aspnetcore-2.2
The runtime searches for the view in the following paths:
/Views/{Controller ...
12
votes
2
answers
6k
views
Get instance of class that relies on DI in Startup class
I am running .NET Core 2.2 app and I have a bit of code that I want to run immediately after the initial setup in Startup.cs. The class relies on a registered type and I don't really understand how I ...
11
votes
1
answer
15k
views
Getting IConfiguration in own ServiceCollection
Im making fixture to my tests.
In my FixtureFactory im making my own ServiceCollection:
private static ServiceCollection CreateServiceCollection()
{
var services = new ...
11
votes
2
answers
2k
views
What is limiting the port range for HTTPS in .NET Core 2.2?
In the launchSettings.json I have the following. It works and I can access Swagger and the rest of the page using https://localhost:44300.
{ ...
"iisSettings": {
"windowsAuthentication": false, ...
11
votes
1
answer
7k
views
.Net standard version for .Net core 2.2
Googled a bit but couldn't find the .Net standard version for .Net core 2.2. Only version I got is,
Any hint please?
11
votes
3
answers
3k
views
Empty href after upgrading to asp.net core 2.2
We have built an ASP.NET Core 2.1 website where URLs like www.example.org/uk and www.example.org/de determine what resx file and content to show. After upgrading to ASP.NET Core 2.2, pages load but ...
11
votes
1
answer
12k
views
ANCM InProcess startup failed because of invalid runtimeconfig.json [duplicate]
The application is deployed as an (32-bit, .NET Core 2.2) App Service on Azure. It works fine when using the standard AspNetCoreModule instead of the newer AspNetCoreModuleV2 that supports the ...
10
votes
2
answers
7k
views
Get current User outside of Controller
On an ASP.NET Core 2.2 controller I have the following:
var principal = this.User as ClaimsPrincipal;
var authenticated = this.User.Identity.IsAuthenticated;
var claims = this.User.Identities....
10
votes
3
answers
20k
views
Get the Controller Name and Method Name in ASP.NET-Core 2.2 Controller
I know that in asp.net-core 2.2, I can get the action name as follows:
ControllerContext.ActionDescriptor.ActionName
but I am looking for a way to get the controller name of the current request/page ...
10
votes
1
answer
8k
views
Self-Contained ASP.Net Core Not Reading appsettings.json file
I wrote a ASP.Net Core 2.2 application. Everything works fine when I run it on my dev machine.
I have published and deployed it to my staging machine as a self-contained application.
The ...