Skip to main content

Questions tagged [httpcontext]

HttpContext is a class from .NET Framework which provides information about an HTTP request.

0 votes
0 answers
10 views

ASP.NET Core 8 : singleton pattern with HttpContextAccessor does not work together

I'm developing an ASP.NET Core 8 application and using the singleton pattern for session management, but when I want to read the values, it displays null values! Here you can see the code: ...
Mohamad Ghafari's user avatar
0 votes
0 answers
18 views

HttpContext session data return null after published API from React App

I am using asp.net core web api for backend and React for frontend.I use HttpContext for session in api in post method. when i published api, i can get response from postman for HttpContext session. ...
percy's user avatar
  • 11
1 vote
1 answer
50 views

.NET 8 Middleware Unexpectedly Changes Status Code to 204 After _next(context)

I am working on a .NET 8 Webapp. I have implemented a middleware to log requests and responses, but I'm facing an issue where the status code is unexpectedly changing from 200 to 204 after calling ...
Asad's user avatar
  • 93
1 vote
1 answer
77 views

How to redirect an exception that was caught by a middleware back to a controller's action method in C# ASP.NET Core?

Lately, I have been trying to implement a strategy for dealing with exceptions in my C# ASP.NET Core application with no success. This strategy is structured in two parts: The first is to have a piece ...
Philipe Riskalla Leal's user avatar
4 votes
2 answers
128 views

Should IHttpContextAccessor be avoided? Getting user information into a DI service

There is a lot of information about using IHttpContextAccessor to inject user information in a DI service. However, there is a warning on this interface that suggests it should be used with caution. ...
JamesB's user avatar
  • 305
2 votes
1 answer
59 views

How to properly mock HttpContextAccessor with Request.Form for controller testing in .NET 6

I have the following code for mocking the HttpContextAccessor. Most of it works fine but the area that I can't get to work as expected is getting form values, specifically when trying to get them ...
geoff swartz's user avatar
  • 5,845
0 votes
0 answers
57 views

ASP.NET Core 5/6/7 MVC is losing HttpContext

For a while now we are experiencing an error with the HttpContext in our platform. To be more exact the HttpContext information is being lost. Our platform uses IIS, Docker Desktop and .Net (5, 6 and ...
user25147906's user avatar
0 votes
1 answer
37 views

How to pass IHttpContextAccessor as parameter to ValidationClass' Method

I have a class for Validation which is: public class PageValidation:ValidationAttribute { private readonly string UserKey; private readonly HttpContext _context; public PageValidation(...
Yunus Mert Çakar's user avatar
0 votes
1 answer
177 views

ASP.NET - HttpResponse.WriteAsync() vs HttpResponse.Body.WriteAsync() vs HttpResponse.BodyWriter.WriteAsync()

In ASP.NET one has three options (that I know of) for writing directly to the response buffer. Given the following data: var str = "Hello World"; var bytes = Encoding.UTF8.GetBytes(str); We ...
user3163495's user avatar
  • 3,285
0 votes
1 answer
59 views

User.Identity.IsAuthenticated always false and User.Identity.Claims is null in .NET Core JWT Auth

Program.cs: builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters ...
Ahmed Borno's user avatar
0 votes
0 answers
49 views

Why don't form fields get returned from this HttpContext mock

I tried to mock the HttpContext for unit tests for a .net 6 web app. What's interesting is that I can get any files added to the FileCollection. However, if I try to access the form fields, it ...
geoff swartz's user avatar
  • 5,845
1 vote
2 answers
65 views

How can I access session data in Asp.net MVC Core 7?

I'm in the process of migrating a huge project from .net4.8 to .net7. The solution is basically a tiny web core project called Investo, but it references a huge project called General. 99% of the ...
Yisroel M. Olewski's user avatar
0 votes
1 answer
123 views

Blazor - Read a cookie value in pre-rendering and OnInitializeAsync

I have a Blazor Server .NET 8 web application that uses/calls a DLL for various tasks including retrieving and reading the value of a cookie. Basically, the DLL used HttpContext, which is not always ...
Arkinala's user avatar
0 votes
0 answers
66 views

Blazor - Using HttpContext in a DLL

I have a Blazor Server .NET 8 web application that uses HttpContext for some tasks. At first, I can access HttpContext without any problem, then the code executes a second time (pre-render?) and ...
Arkinala's user avatar
1 vote
0 answers
32 views

Strange behaviour with StreamContent with Reverse Proxy redirection of HttpContext

I'm developing Reverse Proxy inside Asp.Net Core API. When I'm using StreamContent like this: if (IsContentMethod(request.Method) && !string.IsNullOrEmpty(requestBody)) { ...
h0use's user avatar
  • 111

15 30 50 per page
1
2 3 4 5
78