313 questions
1
vote
0
answers
53
views
ASP.NET Core 7: BouncyCastle conflict `MissingMethodException` - binding redirects ineffective?
I'm encountering a frustrating dependency conflict in my ASP.NET Core 7 application involving different versions of BouncyCastle, and standard resolution techniques like binding redirects don't seem ...
3
votes
1
answer
82
views
ASP.NET Core 7 Web API : optional query parameters not captured by ApiController
I have an ASP.NET Core 7 Web API service implemented in C# and a method defined like this:
[ApiController]
[Route("api/[controller]")]
public class SensorsController : ControllerBase
{
//...
0
votes
1
answer
62
views
Controller class does not get called when using Azure authentication
Short problem description: I can't make an internal API call to my controller class after using M365 authentication when starting my app. Retrieving ID or access token has not worked so far and ...
0
votes
1
answer
59
views
ASP.NET Core 7 MVC : how to submit IEnumerable model to controller?
I have simple grid filled from an IEnumerable model and I can't pass it to the controller:
@model IEnumerable<SkupinaKlientiVykazyModel>
<form method="post" asp-action="...
1
vote
1
answer
104
views
Using EF Core DbContext and ASP.NET Core Identity's UserManager simultaneously
My user entity:
public class User : IdentityUser<long>
{
public Office Office { get; set; } // not nullable
// ...other custom properties
}
Suppose I want to create a new user:
var ...
1
vote
2
answers
125
views
Register types from assembly scan against interface and implementation in ASP.NET Core DI
To register some service against both interface and implementation:
services.AddSingleton<IFoo, Foo>();
services.AddSingleton<Foo>(x => x.GetRequiredService<IFoo>());
That ...
0
votes
0
answers
28
views
ASP.NET Core 7 MVC - how to implement identity my project? [duplicate]
(sorry for my bad English)
I had previously created an ASP.NET Core 7 MVC project and installed the dashboard. However, now I want to do authentication and authorization with the Microsoft.Identity ...
3
votes
1
answer
669
views
Does .NET Core IServiceScopeFactory child scope dispose transient services?
Whenever I need transient or scoped services inside a singleton or background service, I create them in a child scope:
using var serviceScope = _serviceScopeFactory.CreateScope();
var foo = ...
0
votes
1
answer
471
views
ASP.NET Core 7 Web API integration tests - WithHostBuilder breaking database connection
I'm working on an ASP.NET Core 7 Web API, and I'm writing integration tests using CustomWebApplicationFactory.
My program is making some external HTTP calls, so I want to mock them in my tests. I want ...
0
votes
1
answer
58
views
Optionally invoke tag helpers in Razor page
This select will be populated normally:
<select ... [email protected] asp-items=Model.Products>
</select>
Sometimes I want to render it as empty; I tried:
<select ... @if (!...
0
votes
0
answers
49
views
Custom tag helper automatically removes attributes from markup
Consider a custom tag helper with this:
[HtmlTargetElement("a", Attributes = "custom")]
public class CustomTagHelper : TagHelper
{
[HtmlAttributeName("foo")]
public ...
0
votes
1
answer
59
views
Setting lifespan of session in .NET 7.0 webapp
I am rather new to .NET and I am trying to leave a session cookie in the browser and set its timespan.
This is my Program.cs, more or less taken from tutorials and StackOverflow answers I found:
using ...
0
votes
0
answers
159
views
In-memory & Client Side Caching
I am trying to check how the caching works in in-memory and client side using .NET 7.0. For in-memory caching, I keep the results from database in a cached object and when the object expires it ...
3
votes
1
answer
105
views
Why should change the first letter of the property to lowercase when updating the project to .NET 8?
I used .NET 7.x (ASP.NET Core 7 MVC) and JavaScript Library v1.10.2 and use XHR in Ajax to get data from the controller as shown here.
Send a request to get data like this:
function ...
0
votes
1
answer
58
views
Remove querystring from ASP.NET Core Identity's 403 page
I'm using ASP.NET Core Razor Pages with Identity.
When a user navigates to some authorised route /secret (which he cannot access), the 403 page is shown as expected, but the runtime appends ?ReturnUrl=...
1
vote
0
answers
170
views
How to lowercase all routes including areas and Identity in ASP.NET Core 7 MVC?
I have /Admin/Home
But I need /admin/home
I tried many methods and nothing worked. I've been sitting on this for a long time, I hope someone can help me.
I tried using the following:
services....
0
votes
1
answer
526
views
Separate status code pages in ASP.NET Core Razor Pages
I'm using ASP.NET Core Razor Pages with Identity. I use the StatusCodePages middleware in the standard way:
app.UseStatusCodePagesWithReExecute("/Error", "?statusCode={0}");
In ...
2
votes
1
answer
128
views
ASP.NET Core Identity interferes with StatusCodePages 404 middleware
I'm using ASP.NET Core Razor Pages 7 with Identity. Suppose I navigate to:
/non-existent-page
I expect it to show the 404 page, but it actually redirects to the login page and shows:
/login/?return=%...
3
votes
1
answer
472
views
Disable wss for ASP.NET Core Hot Reload
I'm using ASP.NET Core's hot reload feature. It tries to connect with two websockets: ws and wss.
The ws connection succeeds and hot reload works. But I'm not using HTTPS in my local development ...
0
votes
1
answer
188
views
Generate URL in ASP.NET Core given URL path and route values
If I have a "page name" or "route name", and also route values, then I could create a URL in various ways:
return RedirectToPage
return RedirectToRoute
Url.Action
Url.ActionLink
...
1
vote
1
answer
378
views
ASP.NET Core Web API : redirection to Angular
It seems the Angular redirection from with-in ASP.NET Core Web API is not working in a shared deployment. I am using ASP.NET Core 7 for the Web API. The current setup works perfectly with ASP.NET Core ...
1
vote
1
answer
130
views
Multiple ways of writing DataAnnotations custom validators
I wrote a custom DataAnnotations validator (for client and server):
public class CustomAttribute : ValidationAttribute, IClientModelValidator { /* ... */ }
However the docs show an alternate approach,...
0
votes
1
answer
51
views
Replicate asp-for functionality on any element
ASP.NET Core's <input> and <label> tag helpers support the asp-for property, which generates id, name and for appropriately.
Is it possible to get those values somehow and use them on some ...
0
votes
1
answer
65
views
ASP.NET Core 7 MVC : adding more detail, attributes, or something to extend exception handler page
I'm using the exception handler page as described in the provided link. However the ExceptionHandlerPathFeature doesn't provide all the details I'd like to use. This app is an ASP.NET Core 7 MVC web ...
0
votes
1
answer
240
views
ASP.Net Core 7.0 Web App (Model-View-Controller) ErrorViewModel OnGet OnPost do not get called or executed
I've been struggling with setting up global error handling for my ASP.Net Core MVC Web App. I've been trying to apply the following article and I've had no luck.
https://learn.microsoft.com/en-us/...
0
votes
1
answer
777
views
Error when trying to run an integration test
When trying to run an integration test in .NET 7.0, I'm facing the following issue:
An assembly specified in the application dependencies manifest (testhost.deps.json) was not found:
package: '...
0
votes
2
answers
343
views
ASP.NET Core 7 : edit requests to controller with large request returns 400 error
I'm using ASP.NET Core 7. I have an update form which results in an http 400 error for large dataset updates. It works fine when the data being updated is smaller. The error I get is
This page isn't ...
0
votes
0
answers
58
views
Windows Service incorrectly executes utility executable instead of main application in ASP.NET Core 7.0
I encountered an issue while configuring an ASP.NET Core 7.0 web application to run as a Windows Service (Windows 11), following the official Microsoft guide: Host ASP.NET Core in a Windows Service
...
1
vote
1
answer
329
views
How does AddRazorPages add support for MVC + views?
I want to use Razor Pages and "MVC with views" simultaneously.
So I used services.AddRazorPages() (which gives RazorPages and WebAPI) and then services.AddControllersWithViews() (which gives ...
1
vote
1
answer
89
views
Using partial view or refresh whole page?
I have an ASP.NET Core 7 MVC project that has layout that looks like this.
Image
Default URL will be https://myurl/Home.
My question is: when I click any menu at left tab to navigate to the page, what ...
0
votes
0
answers
83
views
Generate OTP and verify feature for dev/qa environments
Our application backend is an ASP.NET Core 7 Web API, frontend is React.
I need to generate an OTP and send to a valid mobile phone number and then verify it. Is this not feasible for an application ...
1
vote
2
answers
517
views
Razor Page page model file without corresponding content file
I'm using Razor Pages. Sometimes I need a page model file without the corresponding content file. But I must nonetheless specify a route for that page, and so define a content file anyway, just for ...
0
votes
2
answers
117
views
multipartdataformcontent not working on razor page but works in swagger
I'm following microsoft's example for file upload operation in my blazor server project. And my API works in Swagger, in the page no files are transferred to my API layer.
Here is my code - Razor page:...
1
vote
0
answers
59
views
When can methods in UrlHelperExtensions return null?
I use the Url.Page methods from UrlHelperExtensions. They return string?, which trigger analysers in my code.
When can those methods return null? The class docs do not say.
0
votes
1
answer
145
views
Resolve custom IdentityErrorDescriber from ASP.NET Core DI
I created a custom IdentityErrorDescriber based on this approach, and registered it like so:
services
.AddIdentityCore<CustomUser>()
.AddErrorDescriber<CustomIdentityErrorDescriber>()
...
0
votes
0
answers
334
views
Different values for ASP.NET Core auth cookie's ExpireTimeSpan and Cookie.MaxAge
ASP.NET Core's cookie middleware can be configured like so:
builder.Services.ConfigureApplicationCookie(x => {
x.SlidingExpiration = true; // the default
x....
0
votes
0
answers
112
views
return View in .net core show that (IFeatureCollection has been disposed. Object name: 'Collection')
Somebody help me please.
I'm using .net core 7.
My register process works well. But I'm not able to return View.
I use the Unit of Work pattern in Data Access Layer.
Here is my IUnitOfWork.cs (from ...
-1
votes
1
answer
267
views
ASP.NET Core 7 project takes long time on first load in production
I have an ASP.NET Core 7 Razor pages project. It works fine on localhost, but when I upload the project to my web server on the internet, the first time it loads, it takes a few seconds to load the ...
0
votes
1
answer
477
views
Disable ASP.NET Core hot reload script from frontend
Sometimes I make changes in my IDE and don't want the page to be reloaded in the browser after I save. A typical scenario is that I make changes to the page via the devtools, and if the page is ...
0
votes
0
answers
99
views
HttpRequestException on published ASP.NET Core application
I have an ASP.NET Core MVC and Web API combined project that's published to IIS. Whenever an API call is made using HttpClient, I get a status 500 on the webpage. Logging the exception shows:
System....
1
vote
3
answers
5k
views
How do I get access to IMemoryCache in Program.cs in Asp.Net Core
I am in .Net 7.0 and in Program.cs we do not have any functions where there is a scope for dependency injection. The code is directly as follow:
using Microsoft.AspNetCore.Mvc;
using Microsoft....
3
votes
2
answers
300
views
Getting "Running scripts is disabled on this system." in ASP.NET Core Web API
I am trying to run PowerShell script from ASP.NET Core Web API. Please see the environment details below:
.NET SDKs installed:
3.1.403 [C:\Program Files\dotnet\sdk]
7.0.200 [C:\Program Files\...
1
vote
0
answers
572
views
Entity Framework Core database migration in Kubernetes
k8s cluster on premises. 3x master, 2x worker nodes.
I need to deploy 5x of my service replicas to my cluster.
Service is an ASP.NET Core 7 Web API, using Entity Framework Core. When the API starts, ...
0
votes
1
answer
649
views
Retrieve spatial data from SQL Server to ASP.NET Core 7 using C# and NetTopologySuite
What is the correct way to retrieve spatial data from SQL Server and use it in my C# code?
I am using the aspnetzero Angular web framework with the following related packages:
net7.0
Microsoft....
-1
votes
1
answer
123
views
ASP.NET Core 7 IResults usage
Please I'd like to know why I can't use the namespace Microsoft.AspNetCore.Http.HttpResults, but I can use Microsoft.AspNetCore.Http.Results namespace has the Results class which gives us different ...
0
votes
0
answers
71
views
nested group by in LINQ give me "The LINQ expression could not be translated"
this query for make list of department every department have list of Employees then every employee has list of data about his attendance
for that I use nested group in multiple layer then use nested ...
1
vote
1
answer
398
views
How to get ASP.NET Core to bind to simple data types
I am in the process of migrating a medium-sized .NET 4, ASP.NET MVC (old) application to .NET 7, ASP.NET Core MVC (new).
I have a quite a few controllers with action methods that use simple types for ...
0
votes
1
answer
373
views
ASP.NET Core MVC Empty Request Body .NET 7
I get an empty Request.Body in the controller when I make a request to the controller from the frontend part, but if I use Postman, then everything works. When I sent request from Firefox, request ...
-1
votes
1
answer
132
views
Invalid Signature JWT in .Net Core 7
I always get invalid signature when I input the generated token in jwt.io Here is my code for making the token:
private string GenerateJwtToken(string userID, string username, string issuer, string ...
0
votes
0
answers
24
views
Trying to run GraphQL in asp .net 7 app always crashes
So I would like to get my GraphQL app running on an asp .net core 7 app, but the program always crashes. I cant seem figure out what is wrong with this. Not even the event viewer tells any useful ...