Search code examples
asp.netdnsquartz

ASP.NET :How to get the domain name of server in a Quartz Job?


My website runs on IIS in integrated mode(.Net 4.5).
I want to send emails in a Quartz job. Each email has a hyperlink to my website. I need to get the domain name in the job ,so the server can create the hyperlink dynamically.
But my colleagues told me that it is not possible to get the domain name without receiving a request, which means I must get HttpContext.Current.Request.Url for resolving the domain name.

My question is: Is it possible to get the domain name in a Quartz job? Why?

Thanks a lot.


Solution

  • No it is not. A Quartz job does not have an HttpContext because they run in a different thread. You can try

    System.Web.Hosting.HostingEnvironment.SiteName
    

    or

    Dns.GetHostName()
    

    Those do not give the domain name, but the name of the site in IIS or the Host Name. But maybe you can use that to create the link.

    You can always store the domain with the data that the Quartz job uses to send the mail. That would be the safest solution.