tagged [httpcontext]

How to avoid a HttpException when calling HttpContext.Request?

How to avoid a HttpException when calling HttpContext.Request? So [HttpContext.Request](http://msdn.microsoft.com/en-us/library/system.web.httpcontext.request%28v=vs.110%29.aspx) throws if called with...

18 Apr at 01:56

Read Http Request into Byte array

Read Http Request into Byte array I'm developing a web page that needs to take an HTTP Post Request and read it into a byte array for further processing. I'm kind of stuck on how to do this, and I'm s...

28 Aug at 16:14

HttpContext not available in Class Library

HttpContext not available in Class Library I am working on a project where I have a C# class library which needs to use the `System.web.HttpContext`. I've done this before in another project without p...

4 Jan at 01:20

Get current System.Web.UI.Page from HttpContext?

Get current System.Web.UI.Page from HttpContext? This is actually a two part question. First,does the HttpContext.Current correspond to the current System.UI.Page object? And the second question, whic...

7 Apr at 00:1

HttpContext.Current not Resolving in MVC 4 Project

HttpContext.Current not Resolving in MVC 4 Project I am wanting to use ImageResizer (from ImageResizing dot net). I installed ImageResizer for MVC via NuGet. But when I go to use the following code fr...

Using HttpContext.Current.Application to store simple data

Using HttpContext.Current.Application to store simple data I want to store a small list of a simple object (containing three strings) in my ASP.NET MVC application. The list is loaded from the databas...

29 Jan at 19:37

Writing to ZipArchive using the HttpContext OutputStream

Writing to ZipArchive using the HttpContext OutputStream I've been trying to get the "new" ZipArchive included in .NET 4.5 (`System.IO.Compression.ZipArchive`) to work in a ASP.NET site. But it seems ...

HttpContext.Current null inside async task

HttpContext.Current null inside async task I have a method that uses a repository (`userRepo`): ``` public override Task CreateLocalUserAsync(IUser user, string password, CancellationToken cancellatio...

1 Oct at 08:43

Testing ServiceStack services with custom factory

Testing ServiceStack services with custom factory I have read excellent article [here](http://www.richardfawcett.net/2012/02/29/accessing-asp-net-session-from-servicestack/) about accessing ASP.NET se...

17 Sep at 15:17

Why is HttpContext.Current null?

Why is HttpContext.Current null? I have a value that I use in all the application; I set this in application_start ``` void Application_Start(object sender, EventArgs e) { Dictionary> Panels = new ...

26 Sep at 02:28

Unified static class between HttpContext and SignalR HubCallerContext

Unified static class between HttpContext and SignalR HubCallerContext I have a lot of code that depends on HttpContext.Current, and I noticed that requests that come from SignalR hubs have `HttpContex...

9 Feb at 13:51

adding header to http response in an action inside a controller in asp.net/mvc

adding header to http response in an action inside a controller in asp.net/mvc I am streaming data from server to client for download using `filestream.write`. In that case what is happening is that I...

19 Apr at 10:2

C# DotNet Core Middleware Wrap Response

C# DotNet Core Middleware Wrap Response I have a simple controller action which looks like: I want to be able to inspect the return value from within the middleware so the JSON would look something li...

8 Nov at 14:49

Correct way to use HttpContext.Current.User with async await

Correct way to use HttpContext.Current.User with async await I am working with async actions and use the HttpContext.Current.User like this ``` public class UserService : IUserService { public ILocPr...

Mock HttpContext.Current in Test Init Method

Mock HttpContext.Current in Test Init Method I'm trying to add unit testing to an ASP.NET MVC application I have built. In my unit tests I use the following code: With the following helpers to mock th...

30 Jun at 08:4

Manually creating an HttpContext in ASP.NET Core 2.x

Manually creating an HttpContext in ASP.NET Core 2.x I'm trying to render a Razor view to a string from a Hosted Service. By using the `IRazorViewEngine` I am able to render a view to a string using s...

HttpContext.Response.Body.Position = 0 - "Specified method is not supported" error

HttpContext.Response.Body.Position = 0 - "Specified method is not supported" error I've got some logging middleware I've setup that grabs and logs information utilizing HttpContext. I need to set the ...

5 Jul at 13:40

How to mock HttpContext.User

How to mock HttpContext.User I am working on a Asp.net MVC 5 project and I am trying to setup a mock to return a custom principal within a controller. I have search and tried different approach sugges...

HttpContextAccessor.HttpContext is null on Linux while non-null on Windows in ServiceStack.Core

HttpContextAccessor.HttpContext is null on Linux while non-null on Windows in ServiceStack.Core I have a simple ServiceStack project that runs on .NET Core 2.0. This works fine on Windows but fails on...

Why is User (as in User.Identity.Name) null in my abstract base controller?

Why is User (as in User.Identity.Name) null in my abstract base controller? I was asking a related question but messed the title up and no-one would understand it. Since I am able now to ask the quest...

Need to add custom header to request in unit test

Need to add custom header to request in unit test I finally was able to get the `HttpContext.Current` to be not null by finding some code online. But I still have not be able to add custom headers to ...

How to use IRequiresRequest to inject IRequest in ServiceStack?

How to use IRequiresRequest to inject IRequest in ServiceStack? I need to access request context, specifically the Items inside my custom class and I don't want to do have it either inheriting from `S...

7 Jun at 00:55

Testing a Web API method that uses HttpContext.Current.Request.Files?

Testing a Web API method that uses HttpContext.Current.Request.Files? I am attempting to write a test for a Web API method that uses `HttpContext.Current.Request.Files` and after exhaustive searching ...