Asp.Net MVC Unique id per request

前端 未结 3 927
醉梦人生
醉梦人生 2021-02-20 00:04

In our MVC 5 site, no session, we need to get/generate a unique ID per request. THhis will be used as an ID for logging all activity in the request.

Is there a way to as

3条回答
  •  滥情空心
    2021-02-20 00:48

    If you need a single value without having to implement something like Guid.NewGuid(), perhaps the HttpContext timestamp will work for you.

    int requestId = System.Web.HttpContext.Current.Timestamp.Ticks;
    

    A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, or 10 million ticks in a second.

    Then this solution should be evaluated according to their circumstances because there is the possibility that two requests fall on the same tick of time.

提交回复
热议问题