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
40
votes
5 answers

How does HttpContext.Current.User.Identity.Name know which usernames exist?

This is not necessarily an issue, I am just curious as to how it works. I have a method: public static bool UserIsAuthenticated() { bool isAuthed = false; try { if (HttpContext.Current.User.Identity.Name != null) { …
Srb1313711
  • 1,767
  • 5
  • 20
  • 32
40
votes
5 answers

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 like it doesn't like writing to the stream of HttpContext.Response.OutputStream. My following code example…
Daniel Sørensen
  • 403
  • 1
  • 5
  • 7
40
votes
3 answers

HttpContext.Current.Request.Url.Host what it returns?

I'm having a local application which has a path: http://localhost:950/m/pages/Searchresults.aspx?search=knife&filter=kitchen but when this goes to integration environment or perhaps the production, it will be something…
Amin Sayed
  • 1,170
  • 2
  • 12
  • 26
38
votes
3 answers

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 ILocPrincipal Current { get { return HttpContext.Current.User as ILocPrincipal; } } } public class…
Markus
  • 3,053
  • 3
  • 20
  • 25
36
votes
6 answers

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 stumped on what is the best way to accomplish. Here is my code so far: public…
Encryption
  • 1,665
  • 7
  • 31
  • 50
36
votes
3 answers

HttpContext.Items with ASP.NET MVC

I'm implimenting my own ApplicationContext class that uses the singleton pattern. I want to store my instance of it in HttpContext.Items, since it is accessible in all parts of the request. I've been reading about using HttpContext with ASP.NET…
Ryan Hoffman
  • 1,096
  • 1
  • 10
  • 22
35
votes
3 answers

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 from the example: //Loop through each uploaded file foreach (string fileKey in…
Nick
  • 457
  • 1
  • 4
  • 8
34
votes
3 answers

What is the WCF equivalent of HttpContext.Current.Request.RawUrl?

I've got some RESTful services running in a pure WCF context (i.e. ASP.NET compatibility is not enabled, and thus there is no HttpContext.Current object available). The URLs to the services are rewritten at the start of the request using an…
Greg Beech
  • 122,952
  • 42
  • 199
  • 241
32
votes
3 answers

access HttpContext.Current from WCF Web Service

I just started using WCF Services with ASP.NET AJAX. I instantiate my WCF service from Javascript and then pass string variables as arguments to my WCF Service method (with an OperationContract signature). I then return a .NET object (defined with…
MacGyver
  • 16,700
  • 37
  • 145
  • 233
29
votes
5 answers

HttpContext on instances of Controllers are null in ASP.net MVC

This may not be the correct way to use controllers, but I did notice this problem and hadn't figured out a way to correct it. public JsonResult SomeControllerAction() { //The current method has the HttpContext just fine bool…
hugoware
  • 33,265
  • 24
  • 58
  • 70
29
votes
6 answers

How can I use System.Web.Caching.Cache in a Console application?

Context: .Net 3.5, C# I'd like to have caching mechanism in my Console application. Instead of re-inventing the wheel, I'd like to use System.Web.Caching.Cache (and that's a final decision, I can't use other caching framework, don't ask…
Ron Klein
  • 8,650
  • 9
  • 50
  • 83
26
votes
7 answers

HttpContext.Current.User.Identity.Name is always string.Empty

Hi I use a custom MembershipProvider. I want to know the current username during an application scenario, but when I try accessing HttpContext.Current.User.Identity.Name it always returns string.Empty. if (Membership.ValidateUser(tbUsername.Text,…
Shimmy Weitzhandler
  • 92,920
  • 119
  • 388
  • 596
25
votes
3 answers

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 problem but now its not working. I'm not sure what I am missing they're both targeting .net 3.5…
Boardy
  • 31,944
  • 94
  • 238
  • 411
24
votes
5 answers

How do I access HttpContext in Server-side Blazor?

I need to access HttpContext in a page (.cshtml) and in particular a request and then a cookie. Despite available, HttpContextAccessor always has a null value stored in its HttpContext property. Any ideas would be much appreciated. Thanks in…
Alexander Christov
  • 7,414
  • 6
  • 36
  • 52
24
votes
10 answers

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 question more precisely, I decided to reformulate it in a new question and close the old one. Sorry for that. So what I want to do…
Masterfu
  • 1,191
  • 2
  • 11
  • 25
1
2
3
69 70