# Use Hangfire job id in the code

**URL:** <https://discuss.hangfire.io/t/use-hangfire-job-id-in-the-code/2621>\
**Category:** question\
**Tags:** sql-server, queues, job-filters\
**Created:** [November 4, 2016, 8:12am UTC](https://discuss.hangfire.io/t/use-hangfire-job-id-in-the-code/2621 "2016-11-04T08:12:36Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![An\_Nguyen](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@An\_Nguyen](https://discuss.hangfire.io/u/An_Nguyen)\
**Post date:** [November 7, 2016, 1:49am UTC](https://discuss.hangfire.io/t/use-hangfire-job-id-in-the-code/2621/2 "2016-11-07T01:49:20Z")

</div>

You can set up a filter class like this:

```
    public class GetJobId : JobFilterAttribute,
        IClientFilter, IServerFilter, IElectStateFilter, IApplyStateFilter
    {
           [ThreadStatic]
            private static string _jobId;
            public static string JobId { get { return _jobId; } set { _jobId = value; } }
            public void OnPerforming(PerformingContext filterContext)
            {
                   _jobId = filterContext.BackgroundJob.Id;
            }
    }

```

And your method like:

```
   [GetJobId ()]
   public void SendEmail(string name)
   {
           string jobId = GetJobId.JobId;
   }

```

Hope this help.

---

_[View the full topic](https://discuss.hangfire.io/t/use-hangfire-job-id-in-the-code/2621)._
