views:

89

answers:

2

Is it possible to retrieve the date/time of a request in ASP.NET (preferably VB.NET)?

I have tried HttpContext.Current.Request.Headers.Get("date"), but it returns nothing (null).

+1  A: 

Well, DateTime.Now will do the job in most circumstances. If you want to know date and time on client machine, you can approximate that by adding/subtracting clients' timezone offset.

Anton Gogolev
Is it possible to get a unique id for an http request? Perhaps I could make this work
craig
@craig: What are you trying to do? `Guid.NewGuid()` is pretty much unique.
Anton Gogolev
+1  A: 

According to w3c there is no "Date" header in HTTP request (but there is one in HTTP response), so you can only determine when ASP.NET've recived paticular request, but not when it was send. If you need time of receiving of a HTTP request you can use DateTime.Now, but how to do this in the best way I can answer only if you will describe you task with more details.

Restuta
I'm creating an sql logger, basically a request comes in and any sql queries get saved to a table in the db. However, I need to somehow group the sql queries per request (as there may be many). I thought that I could get the date/time of the request and compare this each time to see if it was a new request or not. Or if I can get the request.id? that would be brillant.
craig
You can use Guid.NewGuid() method for each request (as described above). Just add a field of type "uniqueidentifier" you database table and save this generated for request identifier.
Restuta