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.

1127 questions
19
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
  • 741
  • 2
  • 7
  • 17
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
  • 111,873
  • 86
  • 233
  • 325
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,825
  • 8
  • 47
  • 60
18
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
  • 4,030
  • 6
  • 34
  • 42
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
  • 111,873
  • 86
  • 233
  • 325
18
votes
2 answers

How to setup Request.Header in FakeHttpContext for Unit Testing

I have a FakeHttpContext I have been trying to modify to include some headers for testing purposes public static HttpContext FakeHttpContext() { var httpRequest = new HttpRequest("", "http://stackoverflow/", ""); var stringWriter = new…
Oluwafemi
  • 14,243
  • 11
  • 43
  • 59
18
votes
4 answers

Request.Url.GetLeftPart(UriPartial.Authority) returns http on https site

We use Request.Url.GetLeftPart(UriPartial.Authority) to get the domain part of the site. This served our requirement on http. We recently change site to https (about 3 days ago) but this still returns with http://.. Urls were all changed to https…
kapz
  • 437
  • 1
  • 7
  • 15
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
  • 33,720
  • 26
  • 113
  • 165
15
votes
4 answers

Determine the URL hostname without using HttpContext.Current?

Using the current request I can get the URL hostname with: HttpContext.Current.Request.Url.Host But - I need to determine the URL hostname without using the current request (HttpContext.Current). The reason for this is that my code is called from a…
Matt Roberts
  • 26,371
  • 31
  • 103
  • 180
15
votes
5 answers

Unit Testing Web Services - HttpContext

I want to write unit tests for a web service. I create my test project, reference my web project (not service reference, assembly reference), then write some code to test the web services - they work fine. However, there are some services which make…
Brandon Montgomery
  • 6,924
  • 3
  • 48
  • 71
15
votes
2 answers

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 HttpContext.Current == null, so my code breaks, for example: HttpContext.Current.Request.IsAuthenticated So I came up with…
formatc
  • 4,261
  • 7
  • 43
  • 81
15
votes
5 answers

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 am able to download the file but it does not appear as download in my browser. Neither the pop-up for "Save As" appears not…
ezile
  • 571
  • 2
  • 6
  • 20
14
votes
2 answers

HttpContext.Current.Session unclear behaviour boolean

I'm having a weird behaviour trying to get the value of a boolean property stored at HttpContext.Current.Session. The object is a boolean. First I'm trying to check if the object exists and, if exists, use it. I'm trying to use it in a ?: operator…
Mario Levrero
  • 3,345
  • 4
  • 26
  • 57
14
votes
1 answer

Injecting HttpContext in Ninject 2

In my asp.net mvc application I'm using Ninject as a DI framework. My HttpAccountService is used by my controllers to get info from and to cookies. For this I need the HttpContext.Current in the HttpAccountService. As this is a dependency I injected…
Boris Callens
  • 90,659
  • 85
  • 207
  • 305
14
votes
1 answer

Storing data in HttpContext.Current.Items vs ViewData

When is it appropriate to store data in HttpContext.Current.Items[...] vs storing data in ViewData[...]? I'm trying to figure out the best practices for storing data in this collection and I'm not sure if it's safe to store user-specific data in…
Petrus Theron
  • 27,855
  • 36
  • 153
  • 287