JSON Statham
JSON Statham

Reputation: 33

This is a bit of a general inquiry, but how can an ASP.NET application know whether a request came from one computer or another?

So let's say I have a controller (sorry, can't type brackets on my computer .. the keyboard is broken)

public ActionResult SomeAction ( string something )
   // ... 

to handles HTTP requests and it is invoked by some on a computer and then invoked by a guy sitting next to him on a different computer. Now I know that in the HttpContext class class there are ways of looking up the IP address, browser languages settings, etc., but none of those are unique to the machine, and because their combination is not necessarily unique to the machine you cannot hash all the info to get some key that you can use for, say, tracking sessions. And yet a Session object exists and somehow knows when two requests came from the same machine. That's where I'm confused.

In other words, what is the key piece of information in an HTTP request that makes the HTTP request unique to the machine sending it?

Upvotes: 1

Views: 54

Answers (1)

driis
driis

Reputation: 164301

This is achieved using session cookies.

When the user first visits your page, ASP .NET issues a session cookie to the browser. On subsequent requests, that session cookie is sent with the request, and by looking at this value, we can tell users apart on the serverside.

Upvotes: 2

Related Questions