Questions tagged [httpcontext]

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

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

1046 questions
22
votes
8 answers

What is the difference between these two HttpContext.Current.Session and Session - asp.net 4.0

What is the difference between these 2 piece of codes. HttpContext.Current.Session["myvariable"] Session["myvariable"] asp.net 4.0 and C# 4.0
MonsterMMORPG
  • 20,310
  • 69
  • 183
  • 306
22
votes
6 answers

How do I retrieve the HttpContext properties when it returns null?

I am doing some asynchronous work on a separate thread using: ThreadPool.QueueUserWorkItem() and in this separate thread, I need to call HttpContext.Current so that I can access: HttpContext.Current.Cache HttpContext.Current.Server …
makstaks
  • 1,974
  • 4
  • 21
  • 38
22
votes
6 answers

What the heck is a context?

I'm starting to see Contexts everywhere I look. In ASP.NET MVC, there are ControllerContexts, RequestContexts, HttpContexts, FormContexts. In Entity Framework, you have ObjectContexts and DbContexts. Ninject has Ninject.Activation.IContext. What…
21
votes
3 answers

HttpContext.Current.Response inside a static method

I have the following static method inside a static class. My question is it safe to use HttpContext.Current.Response inside a static method? I want to be 100% sure that it is thread safe and is only associated with the calling thread.. Does anybody…
Rippo
  • 20,457
  • 13
  • 68
  • 112
20
votes
5 answers

HttpContext.Current is null in my web service

I have a web service (.svc), and I am trying to capture the SOAP request using a piece of code found elsewhere on StackOverflow. The problem is that HttpContext.Current is null, so I can't access Request.InputString. Why is this null, and how can…
Pepito Fernandez
  • 2,116
  • 5
  • 27
  • 43
20
votes
2 answers

System.Web.HttpContext.Current.User.Identity.Name Vs System.Environment.UserName in ASP.NET

What is the difference between System.Web.HttpContext.Current.User.Identity.Name and System.Environment.UserName in the context of a ASP.Net Web Application Project? Here's the code of what I'm trying to do: Database myDB =…
FMFF
  • 1,505
  • 4
  • 28
  • 55
20
votes
3 answers

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 the request in my unit test. Here is my test: [TestClass] public class TagControllerTest { …
19
votes
3 answers

What's the difference between the HttpRuntime Cache and the HttpContext Cache?

I know there is a very similar question here but I was hoping to get a better explination. Why would I ever use HttpContext.Cache instead of HttpRuntime.Cache if the HttpContext really uses the HttpRuntime.Cache behind the scenes? In the article…
Micah
  • 101,237
  • 81
  • 221
  • 320
18
votes
4 answers

ASP.NET MVC: HTTPContext and Dependency Injection

Currently I have an ActionFilter that gets the current users name from HttpContext and passes it into the action which uses it on a service method. eg: Service.DoSomething(userName); I now have a reason to do this not at the action level but the…
anonymous
  • 6,705
  • 8
  • 44
  • 59
18
votes
2 answers

How to use Server.MapPath when HTTPContext .Current is Nothing

I have some code that works fine when I need to delete some image files from a directory on my web server: Dim ImageURL As String = dsImages.Tables(0).Rows(iImgRow).Item("ImageURL") Dim physicalName =…
John Adams
  • 4,573
  • 23
  • 85
  • 124
18
votes
2 answers

How does HttpContext.Current work?

This is kind of a hard question to formulate. I'm wondering how HttpContext.Current gets assigned a unique instance for every request considering it's a static object? Thanks!
Micah
  • 101,237
  • 81
  • 221
  • 320
18
votes
2 answers

HttpSelfHostServer and HttpContext.Current

I'm working on a self-hosted ASP.NET web api-application. Everything works fine, but now I'm struggling with HttpContext: I need to save session-informations from the client. But HttpContext.Current is always null. So it's obvious that my…
Richard
  • 731
  • 1
  • 7
  • 16
17
votes
1 answer

Can you do HtmlDecode & HtmlEncode in Silverlight?

So since System.Web & HttpContext isn't available in Silverlight is there a way to do HtmlDecode & HtmlEncode inside a Silverlight app without some horrendous Regex?
Glenn Slaven
  • 31,855
  • 25
  • 107
  • 163
17
votes
6 answers

Request.Url.Host and ApplicationPath in one call

Is there any way to get HttpContext.Current.Request.Url.Host and HttpContext.Current.Request.ApplicationPath in one call? Something like "full application url"? EDIT: Clarification - what I need is this the part within…
Marcus L
  • 3,892
  • 6
  • 30
  • 39
17
votes
1 answer

Why should I inject IHttpContextAccessor as a Singleton

In all examples that i've seen of IHttpContextAccessor injection, it is set as a Singleton. Examples: How to add IHttpContextAccessor in the Startup class in the DI in ASP.NET Core 1.0? Injecting IHttpContextAccessor into ApplicationDbContext…
Arthur Rizzo
  • 1,247
  • 15
  • 28
1 2
3
69 70