简体   繁体   English

ASP.NET:如何在Quartz Job中获取服务器的域名?

[英]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). 我的网站以集成模式(.Net 4.5)在IIS上运行。
I want to send emails in a Quartz job. 我想在Quartz作业中发送电子邮件。 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. 但是我的同事告诉我,没有收到请求就无法获得域名,这意味着我必须获得HttpContext.Current.Request.Url才能解析域名。

My question is : Is it possible to get the domain name in a Quartz job? 我的问题是 :是否可以在Quartz作业中获取域名? Why? 为什么?

Thanks a lot. 非常感谢。

No it is not. 不它不是。 A Quartz job does not have an HttpContext because they run in a different thread. Quartz作业没有HttpContext,因为它们在不同的线程中运行。 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. 这些不提供域名,而是提供IIS中站点的名称或“主机名”。 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. 您始终可以将域与Quartz作业用于发送邮件的数据一起存储。 That would be the safest solution. 那将是最安全的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM